diff options
Diffstat (limited to 'extraplugins/diagram-definition/org.eclipse.papyrus.umldi.editor/src/org/eclipse/papyrus/umldi/editor/UMLDIModelWizard.java')
-rw-r--r-- | extraplugins/diagram-definition/org.eclipse.papyrus.umldi.editor/src/org/eclipse/papyrus/umldi/editor/UMLDIModelWizard.java | 399 |
1 files changed, 215 insertions, 184 deletions
diff --git a/extraplugins/diagram-definition/org.eclipse.papyrus.umldi.editor/src/org/eclipse/papyrus/umldi/editor/UMLDIModelWizard.java b/extraplugins/diagram-definition/org.eclipse.papyrus.umldi.editor/src/org/eclipse/papyrus/umldi/editor/UMLDIModelWizard.java index 40b856f9dec..8a06e1826cd 100644 --- a/extraplugins/diagram-definition/org.eclipse.papyrus.umldi.editor/src/org/eclipse/papyrus/umldi/editor/UMLDIModelWizard.java +++ b/extraplugins/diagram-definition/org.eclipse.papyrus.umldi.editor/src/org/eclipse/papyrus/umldi/editor/UMLDIModelWizard.java @@ -11,7 +11,6 @@ */ package org.eclipse.papyrus.umldi.editor; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -82,7 +81,6 @@ import org.eclipse.papyrus.umldi.UMLDIFactory; import org.eclipse.papyrus.umldi.UMLDIPackage; import org.eclipse.papyrus.umldi.provider.UMLDIEditPlugin; - import org.eclipse.core.runtime.Path; import org.eclipse.jface.viewers.ISelection; @@ -93,105 +91,109 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; - /** - * This is a simple wizard for creating a new model file. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * This is a simple wizard for creating a new model file. <!-- begin-user-doc + * --> <!-- end-user-doc --> + * * @generated */ public class UMLDIModelWizard extends Wizard implements INewWizard { /** - * The supported extensions for created files. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * The supported extensions for created files. <!-- begin-user-doc --> <!-- + * end-user-doc --> + * * @generated */ - public static final List<String> FILE_EXTENSIONS = - Collections.unmodifiableList(Arrays.asList(UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIEditorFilenameExtensions").split("\\s*,\\s*"))); + public static final List<String> FILE_EXTENSIONS = Collections + .unmodifiableList(Arrays.asList(UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIEditorFilenameExtensions").split( + "\\s*,\\s*"))); /** - * A formatted list of supported file extensions, suitable for display. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * A formatted list of supported file extensions, suitable for display. <!-- + * begin-user-doc --> <!-- end-user-doc --> + * * @generated */ - public static final String FORMATTED_FILE_EXTENSIONS = - UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIEditorFilenameExtensions").replaceAll("\\s*,\\s*", ", "); + public static final String FORMATTED_FILE_EXTENSIONS = UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIEditorFilenameExtensions").replaceAll( + "\\s*,\\s*", ", "); /** - * This caches an instance of the model package. - * <!-- begin-user-doc --> + * This caches an instance of the model package. <!-- begin-user-doc --> * <!-- end-user-doc --> + * * @generated */ protected UMLDIPackage umldiPackage = UMLDIPackage.eINSTANCE; /** - * This caches an instance of the model factory. - * <!-- begin-user-doc --> + * This caches an instance of the model factory. <!-- begin-user-doc --> * <!-- end-user-doc --> + * * @generated */ protected UMLDIFactory umldiFactory = umldiPackage.getUMLDIFactory(); /** - * This is the file creation page. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * This is the file creation page. <!-- begin-user-doc --> <!-- end-user-doc + * --> + * * @generated */ protected UMLDIModelWizardNewFileCreationPage newFileCreationPage; /** - * This is the initial object creation page. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * This is the initial object creation page. <!-- begin-user-doc --> <!-- + * end-user-doc --> + * * @generated */ protected UMLDIModelWizardInitialObjectCreationPage initialObjectCreationPage; /** - * Remember the selection during initialization for populating the default container. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Remember the selection during initialization for populating the default + * container. <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected IStructuredSelection selection; /** - * Remember the workbench during initialization. - * <!-- begin-user-doc --> + * Remember the workbench during initialization. <!-- begin-user-doc --> * <!-- end-user-doc --> + * * @generated */ protected IWorkbench workbench; /** * Caches the names of the types that can be created as the root object. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected List<String> initialObjectNames; /** - * This just records the information. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * This just records the information. <!-- begin-user-doc --> <!-- + * end-user-doc --> + * * @generated */ public void init(IWorkbench workbench, IStructuredSelection selection) { this.workbench = workbench; this.selection = selection; setWindowTitle(UMLDIEditorPlugin.INSTANCE.getString("_UI_Wizard_label")); - setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE.getImageDescriptor(UMLDIEditorPlugin.INSTANCE.getImage("full/wizban/NewUMLDI"))); + setDefaultPageImageDescriptor(ExtendedImageRegistry.INSTANCE + .getImageDescriptor(UMLDIEditorPlugin.INSTANCE + .getImage("full/wizban/NewUMLDI"))); } /** * Returns the names of the types that can be created as the root object. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected Collection<String> getInitialObjectNames() { @@ -199,33 +201,35 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { initialObjectNames = new ArrayList<String>(); for (EClassifier eClassifier : umldiPackage.getEClassifiers()) { if (eClassifier instanceof EClass) { - EClass eClass = (EClass)eClassifier; + EClass eClass = (EClass) eClassifier; if (!eClass.isAbstract()) { initialObjectNames.add(eClass.getName()); } } } - Collections.sort(initialObjectNames, CommonPlugin.INSTANCE.getComparator()); + Collections.sort(initialObjectNames, + CommonPlugin.INSTANCE.getComparator()); } return initialObjectNames; } /** - * Create a new model. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Create a new model. <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected EObject createInitialModel() { - EClass eClass = (EClass)umldiPackage.getEClassifier(initialObjectCreationPage.getInitialObjectName()); + EClass eClass = (EClass) umldiPackage + .getEClassifier(initialObjectCreationPage + .getInitialObjectName()); EObject rootObject = umldiFactory.create(eClass); return rootObject; } /** - * Do the work after everything is specified. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Do the work after everything is specified. <!-- begin-user-doc --> <!-- + * end-user-doc --> + * * @generated */ @Override @@ -237,103 +241,110 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { // Do the work within an operation. // - WorkspaceModifyOperation operation = - new WorkspaceModifyOperation() { - @Override - protected void execute(IProgressMonitor progressMonitor) { - try { - // Create a resource set - // - ResourceSet resourceSet = new ResourceSetImpl(); - - // Get the URI of the model file. - // - URI fileURI = URI.createPlatformResourceURI(modelFile.getFullPath().toString(), true); - - // Create a resource for this file. - // - Resource resource = resourceSet.createResource(fileURI); - - // Add the initial model object to the contents. - // - EObject rootObject = createInitialModel(); - if (rootObject != null) { - resource.getContents().add(rootObject); - } - - // Save the contents of the resource to the file system. - // - Map<Object, Object> options = new HashMap<Object, Object>(); - options.put(XMLResource.OPTION_ENCODING, initialObjectCreationPage.getEncoding()); - resource.save(options); - } - catch (Exception exception) { - UMLDIEditorPlugin.INSTANCE.log(exception); - } - finally { - progressMonitor.done(); + WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { + @Override + protected void execute(IProgressMonitor progressMonitor) { + try { + // Create a resource set + // + ResourceSet resourceSet = new ResourceSetImpl(); + + // Get the URI of the model file. + // + URI fileURI = URI.createPlatformResourceURI(modelFile + .getFullPath().toString(), true); + + // Create a resource for this file. + // + Resource resource = resourceSet.createResource(fileURI); + + // Add the initial model object to the contents. + // + EObject rootObject = createInitialModel(); + if (rootObject != null) { + resource.getContents().add(rootObject); } + + // Save the contents of the resource to the file system. + // + Map<Object, Object> options = new HashMap<Object, Object>(); + options.put(XMLResource.OPTION_ENCODING, + initialObjectCreationPage.getEncoding()); + resource.save(options); + } catch (Exception exception) { + UMLDIEditorPlugin.INSTANCE.log(exception); + } finally { + progressMonitor.done(); } - }; + } + }; getContainer().run(false, false, operation); // Select the new file resource in the current view. // - IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); + IWorkbenchWindow workbenchWindow = workbench + .getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); final IWorkbenchPart activePart = page.getActivePart(); if (activePart instanceof ISetSelectionTarget) { - final ISelection targetSelection = new StructuredSelection(modelFile); - getShell().getDisplay().asyncExec - (new Runnable() { - public void run() { - ((ISetSelectionTarget)activePart).selectReveal(targetSelection); - } - }); + final ISelection targetSelection = new StructuredSelection( + modelFile); + getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + ((ISetSelectionTarget) activePart) + .selectReveal(targetSelection); + } + }); } // Open an editor on the new file. // try { - page.openEditor - (new FileEditorInput(modelFile), - workbench.getEditorRegistry().getDefaultEditor(modelFile.getFullPath().toString()).getId()); - } - catch (PartInitException exception) { - MessageDialog.openError(workbenchWindow.getShell(), UMLDIEditorPlugin.INSTANCE.getString("_UI_OpenEditorError_label"), exception.getMessage()); + page.openEditor( + new FileEditorInput(modelFile), + workbench + .getEditorRegistry() + .getDefaultEditor( + modelFile.getFullPath().toString()) + .getId()); + } catch (PartInitException exception) { + MessageDialog.openError(workbenchWindow.getShell(), + UMLDIEditorPlugin.INSTANCE + .getString("_UI_OpenEditorError_label"), + exception.getMessage()); return false; } return true; - } - catch (Exception exception) { + } catch (Exception exception) { UMLDIEditorPlugin.INSTANCE.log(exception); return false; } } /** - * This is the one page of the wizard. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * This is the one page of the wizard. <!-- begin-user-doc --> <!-- + * end-user-doc --> + * * @generated */ - public class UMLDIModelWizardNewFileCreationPage extends WizardNewFileCreationPage { + public class UMLDIModelWizardNewFileCreationPage extends + WizardNewFileCreationPage { /** - * Pass in the selection. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Pass in the selection. <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ - public UMLDIModelWizardNewFileCreationPage(String pageId, IStructuredSelection selection) { + public UMLDIModelWizardNewFileCreationPage(String pageId, + IStructuredSelection selection) { super(pageId, selection); } /** - * The framework calls this to see if the file is correct. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * The framework calls this to see if the file is correct. <!-- + * begin-user-doc --> <!-- end-user-doc --> + * * @generated */ @Override @@ -341,8 +352,10 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { if (super.validatePage()) { String extension = new Path(getFileName()).getFileExtension(); if (extension == null || !FILE_EXTENSIONS.contains(extension)) { - String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" : "_WARN_FilenameExtension"; - setErrorMessage(UMLDIEditorPlugin.INSTANCE.getString(key, new Object [] { FORMATTED_FILE_EXTENSIONS })); + String key = FILE_EXTENSIONS.size() > 1 ? "_WARN_FilenameExtensions" + : "_WARN_FilenameExtension"; + setErrorMessage(UMLDIEditorPlugin.INSTANCE.getString(key, + new Object[] { FORMATTED_FILE_EXTENSIONS })); return false; } return true; @@ -351,47 +364,45 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public IFile getModelFile() { - return ResourcesPlugin.getWorkspace().getRoot().getFile(getContainerFullPath().append(getFileName())); + return ResourcesPlugin.getWorkspace().getRoot() + .getFile(getContainerFullPath().append(getFileName())); } } /** - * This is the page where the type of object to create is selected. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * This is the page where the type of object to create is selected. <!-- + * begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public class UMLDIModelWizardInitialObjectCreationPage extends WizardPage { /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected Combo initialObjectField; /** - * @generated - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * @generated <!-- begin-user-doc --> <!-- end-user-doc --> */ protected List<String> encodings; /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected Combo encodingField; /** - * Pass in the selection. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Pass in the selection. <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public UMLDIModelWizardInitialObjectCreationPage(String pageId) { @@ -399,8 +410,8 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public void createControl(Composite parent) { @@ -420,7 +431,8 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { Label containerLabel = new Label(composite, SWT.LEFT); { - containerLabel.setText(UMLDIEditorPlugin.INSTANCE.getString("_UI_ModelObject")); + containerLabel.setText(UMLDIEditorPlugin.INSTANCE + .getString("_UI_ModelObject")); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; @@ -446,7 +458,8 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { Label encodingLabel = new Label(composite, SWT.LEFT); { - encodingLabel.setText(UMLDIEditorPlugin.INSTANCE.getString("_UI_XMLEncoding")); + encodingLabel.setText(UMLDIEditorPlugin.INSTANCE + .getString("_UI_XMLEncoding")); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; @@ -472,29 +485,29 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ - protected ModifyListener validator = - new ModifyListener() { - public void modifyText(ModifyEvent e) { - setPageComplete(validatePage()); - } - }; + protected ModifyListener validator = new ModifyListener() { + public void modifyText(ModifyEvent e) { + setPageComplete(validatePage()); + } + }; /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected boolean validatePage() { - return getInitialObjectName() != null && getEncodings().contains(encodingField.getText()); + return getInitialObjectName() != null + && getEncodings().contains(encodingField.getText()); } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ @Override @@ -504,8 +517,7 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { if (initialObjectField.getItemCount() == 1) { initialObjectField.clearSelection(); encodingField.setFocus(); - } - else { + } else { encodingField.clearSelection(); initialObjectField.setFocus(); } @@ -513,8 +525,8 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public String getInitialObjectName() { @@ -529,8 +541,8 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public String getEncoding() { @@ -538,30 +550,33 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * Returns the label for the specified type name. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Returns the label for the specified type name. <!-- begin-user-doc + * --> <!-- end-user-doc --> + * * @generated */ protected String getLabel(String typeName) { try { - return UMLDIEditPlugin.INSTANCE.getString("_UI_" + typeName + "_type"); - } - catch(MissingResourceException mre) { + return UMLDIEditPlugin.INSTANCE.getString("_UI_" + typeName + + "_type"); + } catch (MissingResourceException mre) { UMLDIEditorPlugin.INSTANCE.log(mre); } return typeName; } /** - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ protected Collection<String> getEncodings() { if (encodings == null) { encodings = new ArrayList<String>(); - for (StringTokenizer stringTokenizer = new StringTokenizer(UMLDIEditorPlugin.INSTANCE.getString("_UI_XMLEncodingChoices")); stringTokenizer.hasMoreTokens(); ) { + for (StringTokenizer stringTokenizer = new StringTokenizer( + UMLDIEditorPlugin.INSTANCE + .getString("_UI_XMLEncodingChoices")); stringTokenizer + .hasMoreTokens();) { encodings.add(stringTokenizer.nextToken()); } } @@ -570,22 +585,29 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { } /** - * The framework calls this to create the contents of the wizard. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * The framework calls this to create the contents of the wizard. <!-- + * begin-user-doc --> <!-- end-user-doc --> + * * @generated */ - @Override + @Override public void addPages() { // Create a page, set the title, and the initial model file name. // - newFileCreationPage = new UMLDIModelWizardNewFileCreationPage("Whatever", selection); - newFileCreationPage.setTitle(UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIModelWizard_label")); - newFileCreationPage.setDescription(UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIModelWizard_description")); - newFileCreationPage.setFileName(UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIEditorFilenameDefaultBase") + "." + FILE_EXTENSIONS.get(0)); + newFileCreationPage = new UMLDIModelWizardNewFileCreationPage( + "Whatever", selection); + newFileCreationPage.setTitle(UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIModelWizard_label")); + newFileCreationPage.setDescription(UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIModelWizard_description")); + newFileCreationPage.setFileName(UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIEditorFilenameDefaultBase") + + "." + + FILE_EXTENSIONS.get(0)); addPage(newFileCreationPage); - // Try and get the resource selection to determine a current directory for the file dialog. + // Try and get the resource selection to determine a current directory + // for the file dialog. // if (selection != null && !selection.isEmpty()) { // Get the resource... @@ -594,40 +616,49 @@ public class UMLDIModelWizard extends Wizard implements INewWizard { if (selectedElement instanceof IResource) { // Get the resource parent, if its a file. // - IResource selectedResource = (IResource)selectedElement; + IResource selectedResource = (IResource) selectedElement; if (selectedResource.getType() == IResource.FILE) { selectedResource = selectedResource.getParent(); } // This gives us a directory... // - if (selectedResource instanceof IFolder || selectedResource instanceof IProject) { + if (selectedResource instanceof IFolder + || selectedResource instanceof IProject) { // Set this for the container. // - newFileCreationPage.setContainerFullPath(selectedResource.getFullPath()); + newFileCreationPage.setContainerFullPath(selectedResource + .getFullPath()); // Make up a unique new name here. // - String defaultModelBaseFilename = UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIEditorFilenameDefaultBase"); - String defaultModelFilenameExtension = FILE_EXTENSIONS.get(0); - String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; - for (int i = 1; ((IContainer)selectedResource).findMember(modelFilename) != null; ++i) { - modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; + String defaultModelBaseFilename = UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIEditorFilenameDefaultBase"); + String defaultModelFilenameExtension = FILE_EXTENSIONS + .get(0); + String modelFilename = defaultModelBaseFilename + "." + + defaultModelFilenameExtension; + for (int i = 1; ((IContainer) selectedResource) + .findMember(modelFilename) != null; ++i) { + modelFilename = defaultModelBaseFilename + i + "." + + defaultModelFilenameExtension; } newFileCreationPage.setFileName(modelFilename); } } } - initialObjectCreationPage = new UMLDIModelWizardInitialObjectCreationPage("Whatever2"); - initialObjectCreationPage.setTitle(UMLDIEditorPlugin.INSTANCE.getString("_UI_UMLDIModelWizard_label")); - initialObjectCreationPage.setDescription(UMLDIEditorPlugin.INSTANCE.getString("_UI_Wizard_initial_object_description")); + initialObjectCreationPage = new UMLDIModelWizardInitialObjectCreationPage( + "Whatever2"); + initialObjectCreationPage.setTitle(UMLDIEditorPlugin.INSTANCE + .getString("_UI_UMLDIModelWizard_label")); + initialObjectCreationPage.setDescription(UMLDIEditorPlugin.INSTANCE + .getString("_UI_Wizard_initial_object_description")); addPage(initialObjectCreationPage); } /** - * Get the file from the page. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> + * Get the file from the page. <!-- begin-user-doc --> <!-- end-user-doc --> + * * @generated */ public IFile getModelFile() { |