Open a dialog for editing elements [message #48993] |
Fri, 15 September 2006 11:03  |
Eclipse User |
|
|
|
Originally posted by: mike.2.sbcglobal.net
I am trying to display a dialog for editing elements.
Following this email:
http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg03725.html
and another one that I cannot find now, it suggested that a dialog could
be placed in the getOpenCommand() method and return null for the command.
That works to display the dialog, but it does not work for edits.
Can anybody give me an idea of what to do differently?
I think I need to look at the command that is returned, but I have been
unable to find any documentation on commands.
Any help is appreciated.
thanks,
Mike
|
|
|
|
Re: Open a dialog for editing elements [message #50139 is a reply to message #50021] |
Mon, 18 September 2006 14:11  |
Eclipse User |
|
|
|
Originally posted by: vcciubot.uwaterloo.ca
To learn more about commands, explore the IUndoableOperation type hierachy
to see what type of commands GMF defines. Take a look at
AbstractTransactionalCommand.
NOTE: if you need to return these commands from an EditPolicy they must be
wrapped by an ICommandProxy (this makes a GMF command look like a GEF
command).
hope this helps,
vlad
Here are some steps you should take, substitute your concrete
example accordingly.
Add an editor action in your plugin.xml:
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="false"
id=" ca.uwaterloo.watform.bluenose2.diagram.ui.actions.Bluenose2G enerateVHDLAction "
objectClass=" org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditP art ">
<action
label="Generate VHDL"
class=" ca.uwaterloo.watform.bluenose2.diagram.ui.actions.Bluenose2G enerateVHDLAction "
menubarPath="additions"
enablesFor="1"
id="Bluenose2OpenGenerateVHDLAction">
</action>
</objectContribution>
</extension>
Define a command to edit the particular model element as follows, add more
parameters etc.
public class GenerateVHDLCommand extends AbstractTransactionalCommand {
private EObject modelElement;
public GenerateVHDLCommand(EObject modelElement, TransactionalEditingDomain domain,
String label, List affectedFiles) {
super(domain, label, affectedFiles);
this.modelElement = modelElement;
}
protected CommandResult doExecuteWithResult(
IProgressMonitor progressMonitor, IAdaptable info)
throws ExecutionException {
//example here
return CommandResult.newOKCommandResult(/*VHDLGenerator.generateVHD L( (Pipeline) modelElement)*/);
}
}
in doExecuteWithResult you have read/write access to the model element so
you can do whatever you want.
Create and execute this command from your action:
public void run(IAction action) {
TransactionalEditingDomain domain = mySelectedEditPart
.getEditingDomain();
EObject modelElement = mySelectedEditPart.resolveSemanticElement();
AbstractTransactionalCommand semanticCommand = new GenerateVHDLCommand(
modelElement, domain, "Generate VHDL Command",
Collections.EMPTY_LIST);
try {
OperationHistoryFactory.getOperationHistory().execute(
semanticCommand, null, null);
} catch (ExecutionException e) {
// smth Happend here
}
CommandResult commandResult = semanticCommand.getCommandResult();
if (commandResult.getStatus().isOK()) {
String result = (String) commandResult.getReturnValue();
System.out.println(result);
}
}
On Mon, 18 Sep 2006 15:55:19 +0000, Mike Foster wrote:
> I hate to be a pest, but does anybody have any ideas?
>
> Am I going about it all wrong, or am I in the wrong news group?
>
> I would like to be able to double click on a graphical element and display
> a dialog that the user can edit information about that element or the
> model in general. Like the properties window except in a dialog.
>
> The following code displays the dialog, but I cannot seem to figure out
> how to update the model from here.
>
>
> thanks,
> Mike
>
>
> -----
>
> public class OpenEditorEditPolicy extends OpenEditPolicy {
>
> protected Command getOpenCommand(Request request) {
> EditPart targetEditPart = getTargetEditPart(request);
> if (targetEditPart instanceof IGraphicalEditPart) {
> IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
> View view = editPart.getNotationView();
> if (view != null) {
> EObject element = ViewUtil.resolveSemanticElement(view);
> if (element instanceof Operation) {
> System.out.println("found operation");
> Shell shell = new Shell(SWT.DIALOG_TRIM |
> SWT.PRIMARY_MODAL);
> OperationComposite editor = new OperationComposite(shell,
> SWT.NONE);
> shell.open();
>
> // This makes the system unstable.
> // while (!shell.isDisposed ()) {
> // Display.getCurrent().sleep();
> // }
>
> return new ICommandProxy(new EditOperationCommand(element));
> }
> }
> }
> return null;
> }
> }
|
|
|
Powered by
FUDForum. Page generated in 0.04984 seconds