Create a .xxx_diagram by Action [message #79295] |
Tue, 21 November 2006 09:53  |
Eclipse User |
|
|
|
Originally posted by: julias.frb.br
How one can call the digram creation wizard by a custom Action
(org.eclipse.jface.action.Action)?
Thanks
Julia
|
|
|
|
|
|
|
|
|
|
Re: Create a .xxx_diagram by Action [message #165266 is a reply to message #79587] |
Thu, 13 December 2007 08:20   |
Eclipse User |
|
|
|
Originally posted by: trommas.yahoo.com
Hi Alex and Julia.
First, thank you Julia for posting your solution!
Second, is it possible to create the diagram without launching the
wizard? (The action creates a new diagram with default values)
Best Regards,
Tomas Zijdemans
Julia Sartori wrote:
> Thanks Alex! it worked!! ^^
> (by the way, do you know how to show a grid automatically on the diagram?)
>
> here's the final solution:
>
> public void run() {
> try{
> HiperioncadCreationWizard theWiz = new HiperioncadCreationWizard();
> IStructuredSelection selection = new
> StructuredSelection(RoxUIPlugin.getDefault().getWorkbench(). getActiveWorkbenchWindow().getActivePage().getSelection());
>
>
> theWiz.init(RoxUIPlugin.getDefault().getWorkbench(), selection);
>
> WizardDialog dialog = new
> WizardDialog(RoxUIPlugin.getDefault().getWorkbench().getActi veWorkbenchWindow().getShell(),
> theWiz);
>
> dialog.open();
>
> }catch(Exception e){
> e.printStackTrace();
> }
>
> }
>
> Thanks!!
>
> Alex Shatalin wrote:
>> Hello Julia,
>>
>>> and im getting a NullPointerException on:
>>> at
>>> org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.wiza rds.Editor
>>> WizardPage.initialPopulateContainerNameField(EditorWizardPag e.java:304)
>>
>> Well, I think the selection is null (you can check it in the
>> debugger). You should create StructuredSelection instance passing
>> desired file as a parameter. Then you are calling popup menu on some
>> file the selection is equals to this file, so corresponding parameter
>> will be passed to ???InitDiagramFileAction...
>>
>> -----------------
>> Alex Shatalin
>>
>>
|
|
|
|
|
|
|
|
|
|
Re: Create a .xxx_diagram by Action [message #170396 is a reply to message #170366] |
Tue, 29 January 2008 07:25   |
Eclipse User |
|
|
|
Originally posted by: trommas.yahoo.com
> Sure! just copy a code from diagram partitioning into your own action.
Thanks for helping (again) Alex :)
I've basically just copied the code in (as you can see below). The only
thing that gave an error was:
EditPart targetEditPart = getTargetEditPart(request);
so I replaced it with:
EditPart targetEditPart = selectedElement;
My question is:
What do I put in the run method? - I guess the getOpenCommand have to be
called.. but with what kind of reqest as parameter?
Regards,
Tomas
public class UEMLBaseLaunchEditorAction implements IObjectActionDelegate {
public ClassNodeEditPart selectedElement;
public Shell shell;
public void run(IAction action) {
}
/**
* @generated
*/
protected Command getOpenCommand(Request request) {
EditPart targetEditPart = selectedElement;
if (false == targetEditPart.getModel() instanceof View) {
return null;
}
View view = (View) targetEditPart.getModel();
Style link = view.getStyle(NotationPackage.eINSTANCE
.getHintedDiagramLinkStyle());
if (false == link instanceof HintedDiagramLinkStyle) {
return null;
}
return new ICommandProxy(new OpenDiagramCommand(
(HintedDiagramLinkStyle) link));
}
/**
* @generated
*/
private static class OpenDiagramCommand extends
AbstractTransactionalCommand {
/**
* @generated
*/
private final HintedDiagramLinkStyle diagramFacet;
/**
* @generated
*/
OpenDiagramCommand(HintedDiagramLinkStyle linkStyle) {
// editing domain is taken for original diagram,
// if we open diagram from another file, we should use another
// editing domain
super(TransactionUtil.getEditingDomain(linkStyle),
Messages.CommandName_OpenDiagram, null);
diagramFacet = linkStyle;
}
// FIXME canExecute if !(readOnly && getDiagramToOpen == null), i.e.
// open works on ro diagrams only when there's associated diagram
// already
/**
* @generated
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
try {
Diagram diagram = getDiagramToOpen();
if (diagram == null) {
diagram = intializeNewDiagram();
}
URI uri = EcoreUtil.getURI(diagram);
String editorName = uri.lastSegment()
+ "#" + diagram.eResource().getContents().indexOf(diagram);
//$NON-NLS-1$
IEditorInput editorInput = new URIEditorInput(uri, editorName);
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
page.openEditor(editorInput, getEditorID());
return CommandResult.newOKCommandResult();
} catch (Exception ex) {
throw new ExecutionException("Can't open diagram", ex);
}
}
/**
* @generated
*/
protected Diagram getDiagramToOpen() {
return diagramFacet.getDiagramLink();
}
/**
* @generated
*/
protected Diagram intializeNewDiagram() throws ExecutionException {
Diagram d = ViewService.createDiagram(getDiagramDomainElement(),
getDiagramKind(), getPreferencesHint());
if (d == null) {
throw new ExecutionException("Can't create diagram of '"
+ getDiagramKind() + "' kind");
}
diagramFacet.setDiagramLink(d);
assert diagramFacet.eResource() != null;
diagramFacet.eResource().getContents().add(d);
try {
for (Iterator it = diagramFacet.eResource().getResourceSet()
.getResources().iterator(); it.hasNext();) {
Resource nextResource = (Resource) it.next();
if (nextResource.isLoaded()
&& !getEditingDomain().isReadOnly(nextResource)) {
nextResource.save(EditorDiagramEditorUtil
.getSaveOptions());
}
}
} catch (IOException ex) {
throw new ExecutionException("Can't create diagram of '"
+ getDiagramKind() + "' kind", ex);
}
return d;
}
/**
* @generated
*/
protected EObject getDiagramDomainElement() {
// use same element as associated with EP
return ((View) diagramFacet.eContainer()).getElement();
}
/**
* @generated
*/
protected PreferencesHint getPreferencesHint() {
// XXX prefhint from target diagram's editor?
return EditorDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
}
/**
* @generated
*/
protected String getDiagramKind() {
return "Class";
}
/**
* @generated
*/
protected String getEditorID() {
return "org.ueml.uemlbase.editor.diagram.part.ClassDiagramEditorID";
}
}
public void selectionChanged(IAction action, ISelection selection) {
selectedElement = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection)
selection;
if (structuredSelection.getFirstElement() instanceof ClassNodeEditPart) {
selectedElement = (ClassNodeEditPart) structuredSelection
.getFirstElement();
}
}
}
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
shell = targetPart.getSite().getShell();
}
}
|
|
|
|
|
|
|
|
|
|