001: package newprocess.diagram.part;
002:
003: import org.eclipse.emf.workspace.WorkspaceEditingDomainFactory;
004: import newprocess.diagram.edit.parts.ProcessEditPart;
005:
006: import org.eclipse.core.resources.IFile;
007:
008: import org.eclipse.emf.common.util.URI;
009: import org.eclipse.emf.common.util.WrappedException;
010:
011: import org.eclipse.emf.ecore.EObject;
012:
013: import org.eclipse.emf.ecore.resource.Resource;
014: import org.eclipse.emf.ecore.resource.ResourceSet;
015:
016: import org.eclipse.emf.transaction.TransactionalEditingDomain;
017:
018: import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
019:
020: import org.eclipse.jface.action.IAction;
021:
022: import org.eclipse.jface.dialogs.IDialogSettings;
023: import org.eclipse.jface.dialogs.MessageDialog;
024:
025: import org.eclipse.jface.viewers.ISelection;
026: import org.eclipse.jface.viewers.IStructuredSelection;
027: import org.eclipse.jface.viewers.StructuredSelection;
028:
029: import org.eclipse.jface.wizard.Wizard;
030: import org.eclipse.jface.wizard.WizardDialog;
031:
032: import org.eclipse.ui.IObjectActionDelegate;
033: import org.eclipse.ui.IWorkbenchPart;
034:
035: /**
036: * @generated
037: */
038: public class New_processInitDiagramFileAction implements
039: IObjectActionDelegate {
040:
041: /**
042: * @generated
043: */
044: private IWorkbenchPart myPart;
045:
046: /**
047: * @generated
048: */
049: private IFile mySelectedModelFile;
050:
051: /**
052: * @generated
053: */
054: private IStructuredSelection mySelection;
055:
056: /**
057: * @generated
058: */
059: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
060: myPart = targetPart;
061: }
062:
063: /**
064: * @generated
065: */
066: public void selectionChanged(IAction action, ISelection selection) {
067: mySelectedModelFile = null;
068: mySelection = StructuredSelection.EMPTY;
069: action.setEnabled(false);
070: if (selection instanceof IStructuredSelection == false
071: || selection.isEmpty()) {
072: return;
073: }
074: mySelection = (IStructuredSelection) selection;
075: mySelectedModelFile = (IFile) ((IStructuredSelection) selection)
076: .getFirstElement();
077: action.setEnabled(true);
078: }
079:
080: /**
081: * @generated
082: */
083: public void run(IAction action) {
084: TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
085: .createEditingDomain();
086: ResourceSet resourceSet = editingDomain.getResourceSet();
087: EObject diagramRoot = null;
088: try {
089: Resource resource = resourceSet.getResource(URI
090: .createPlatformResourceURI(mySelectedModelFile
091: .getFullPath().toString(), true), true);
092: diagramRoot = (EObject) resource.getContents().get(0);
093: } catch (WrappedException ex) {
094: New_processDiagramEditorPlugin
095: .getInstance()
096: .logError(
097: "Unable to load resource: " + mySelectedModelFile.getFullPath().toString(), ex); //$NON-NLS-1$
098: }
099: if (diagramRoot == null) {
100: MessageDialog.openError(myPart.getSite().getShell(),
101: "Error", "Model file loading failed");
102: return;
103: }
104: Wizard wizard = new New_processNewDiagramFileWizard(
105: mySelectedModelFile, myPart.getSite().getPage(),
106: mySelection, diagramRoot, editingDomain);
107: IDialogSettings pluginDialogSettings = New_processDiagramEditorPlugin
108: .getInstance().getDialogSettings();
109: IDialogSettings initDiagramFileSettings = pluginDialogSettings
110: .getSection("InisDiagramFile"); //$NON-NLS-1$
111: if (initDiagramFileSettings == null) {
112: initDiagramFileSettings = pluginDialogSettings
113: .addNewSection("InisDiagramFile"); //$NON-NLS-1$
114: }
115: wizard.setDialogSettings(initDiagramFileSettings);
116: wizard.setForcePreviousAndNextButtons(false);
117: wizard.setWindowTitle("Initialize new "
118: + ProcessEditPart.MODEL_ID + " diagram file");
119:
120: WizardDialog dialog = new WizardDialog(myPart.getSite()
121: .getShell(), wizard);
122: dialog.create();
123: dialog.getShell().setSize(
124: Math.max(500, dialog.getShell().getSize().x), 500);
125: dialog.open();
126: }
127:
128: }
|