aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarwa rostren2013-09-11 04:08:41 (EDT)
committerEd.Willink2013-09-21 03:08:28 (EDT)
commite4aba493ded8e7ca7753a54d663deaa894c17dbe (patch)
tree653245dec3cc2bc68ace38652a37b2e45ad485d0
parent93ad4c8d8c842389b0bf6e31774425b92d668266 (diff)
downloadorg.eclipse.ocl-e4aba493ded8e7ca7753a54d663deaa894c17dbe.zip
org.eclipse.ocl-e4aba493ded8e7ca7753a54d663deaa894c17dbe.tar.gz
org.eclipse.ocl-e4aba493ded8e7ca7753a54d663deaa894c17dbe.tar.bz2
Add Create Complete OCL File wizardrefs/changes/49/15249/4
Change-Id: I42345bb7dce13a14ef1721fe2b74ef5b4b5abf4a Signed-off-by: marwa rostren <mrostren@obeo.fr>
-rw-r--r--examples/org.eclipse.ocl.examples.ui/META-INF/MANIFEST.MF10
-rw-r--r--examples/org.eclipse.ocl.examples.ui/build.properties3
-rw-r--r--examples/org.eclipse.ocl.examples.ui/icons/OCLModelFile.gifbin0 -> 558 bytes
-rw-r--r--examples/org.eclipse.ocl.examples.ui/plugin.properties4
-rw-r--r--examples/org.eclipse.ocl.examples.ui/plugin.xml18
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/dialogs/ExtendedNewCompleteOCLFileDialog.java622
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerContentProvider.java123
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerSelectionGroup.java356
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ResourceAndContainerGroup.java521
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.java69
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.properties51
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreation.java88
-rw-r--r--examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreationPage.java378
-rw-r--r--plugins/org.eclipse.ocl.common.ui/icons/OCLModelFile.gifbin0 -> 558 bytes
-rw-r--r--plugins/org.eclipse.ocl.common.ui/src/org/eclipse/ocl/common/ui/internal/Activator.java151
-rw-r--r--plugins/org.eclipse.ocl.common/META-INF/MANIFEST.MF3
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/.classpath7
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/.project28
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/META-INF/MANIFEST.MF15
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/build.properties5
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForPerformFinishTest.java54
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForTest.java37
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardNewCompleteOCLFileCreationForTest.java32
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/Test.ecore4
-rw-r--r--tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/WizardNewCompleteOCLCreationPageTest.java204
26 files changed, 2785 insertions, 5 deletions
diff --git a/examples/org.eclipse.ocl.examples.ui/META-INF/MANIFEST.MF b/examples/org.eclipse.ocl.examples.ui/META-INF/MANIFEST.MF
index b6fdaf5..870aa0d 100644
--- a/examples/org.eclipse.ocl.examples.ui/META-INF/MANIFEST.MF
+++ b/examples/org.eclipse.ocl.examples.ui/META-INF/MANIFEST.MF
@@ -8,7 +8,13 @@ Bundle-Version: 1.1.100.qualifier
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)",
- org.eclipse.xtext.ui;bundle-version="[2.0.0,3.0.0)"
+ org.eclipse.xtext.ui;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.ocl.common.ui;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
+ org.eclipse.emf.ecore.editor;bundle-version="2.9.0",
+ org.eclipse.equinox.bidi;bundle-version="[0.10.0,2.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Export-Package: org.eclipse.ocl.examples.ui
+Export-Package: org.eclipse.ocl.examples.ui,
+ org.eclipse.ocl.examples.ui.dialogs,
+ org.eclipse.ocl.examples.ui.messages,
+ org.eclipse.ocl.examples.ui.wizards
diff --git a/examples/org.eclipse.ocl.examples.ui/build.properties b/examples/org.eclipse.ocl.examples.ui/build.properties
index a57f2dd..b43635d 100644
--- a/examples/org.eclipse.ocl.examples.ui/build.properties
+++ b/examples/org.eclipse.ocl.examples.ui/build.properties
@@ -14,5 +14,6 @@ bin.includes = META-INF/,\
.,\
about.html,\
plugin.properties,\
- plugin.xml
+ plugin.xml,\
+ icons/
src.includes = about.html
diff --git a/examples/org.eclipse.ocl.examples.ui/icons/OCLModelFile.gif b/examples/org.eclipse.ocl.examples.ui/icons/OCLModelFile.gif
new file mode 100644
index 0000000..2945103
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/icons/OCLModelFile.gif
Binary files differ
diff --git a/examples/org.eclipse.ocl.examples.ui/plugin.properties b/examples/org.eclipse.ocl.examples.ui/plugin.properties
index 7387a76..538c46f 100644
--- a/examples/org.eclipse.ocl.examples.ui/plugin.properties
+++ b/examples/org.eclipse.ocl.examples.ui/plugin.properties
@@ -7,7 +7,11 @@
#
# Contributors:
# E.D.Willink - initial API and implementation
+# Obeo - complete OCL File Strings externalization
###############################################################################
pluginName = OCL Examples User Interface
providerName = Eclipse Modeling Project
+
+MF_COMPLETE_OCL_WIZARD_NAME = Complete OCL File
+MF_COMPLETE_OCL_WIZARD_DESCRIPTION = Create a new Complete OCL File \ No newline at end of file
diff --git a/examples/org.eclipse.ocl.examples.ui/plugin.xml b/examples/org.eclipse.ocl.examples.ui/plugin.xml
index 9196941..756fd5f 100644
--- a/examples/org.eclipse.ocl.examples.ui/plugin.xml
+++ b/examples/org.eclipse.ocl.examples.ui/plugin.xml
@@ -10,5 +10,23 @@
properties="resourceSetAvailable"
type="java.lang.Object"/>
</extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.eclipse.ocl.ui.wizards"
+ name="OCL">
+ </category>
+ <wizard
+ category="org.eclipse.ocl.ui.wizards"
+ class="org.eclipse.ocl.examples.ui.wizards.WizardNewCompleteOCLFileCreation"
+ icon="icons/OCLModelFile.gif"
+ id="org.eclipse.ocl.ui.wizardNewCompleteOCLFileCreation"
+ name="%MF_COMPLETE_OCL_WIZARD_NAME"
+ project="false">
+ <description>
+ %MF_COMPLETE_OCL_WIZARD_DESCRIPTION
+ </description>
+ </wizard>
+ </extension>
</plugin>
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/dialogs/ExtendedNewCompleteOCLFileDialog.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/dialogs/ExtendedNewCompleteOCLFileDialog.java
new file mode 100644
index 0000000..2304c6e
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/dialogs/ExtendedNewCompleteOCLFileDialog.java
@@ -0,0 +1,622 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ * references WizardNewFileCreationPage, ResourceDialog and ExtendedLoadResourceDialog
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.ui.dialogs;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.EMFPlugin;
+import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
+import org.eclipse.emf.ecore.plugin.EcorePlugin;
+import org.eclipse.emf.ecore.presentation.EcoreActionBarContributor.ExtendedLoadResourceAction.ExtendedLoadResourceDialog;
+import org.eclipse.emf.ecore.presentation.EcoreActionBarContributor.ExtendedLoadResourceAction.RegisteredPackageDialog;
+import org.eclipse.emf.ecore.presentation.EcoreActionBarContributor.ExtendedLoadResourceAction.TargetPlatformPackageDialog;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ocl.common.ui.internal.Activator;
+import org.eclipse.ocl.examples.ui.internal.ripoffs.ResourceAndContainerGroup;
+import org.eclipse.ocl.examples.ui.messages.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+
+public class ExtendedNewCompleteOCLFileDialog
+ extends ExtendedLoadResourceDialog {
+
+ // constants
+ private static final int SIZING_TEXT_FIELD_WIDTH = 250;
+
+ private static final int SIZING_CONTAINER_GROUP_HEIGHT = 120;
+
+ public static final String PREFIX = Activator.PLUGIN_ID + "."; //$NON-NLS-1$
+
+ private static final String NEW_FILE_WIZARD_PAGE = PREFIX
+ + Messages.WizardNewCompleteOCLFileCreationPage_newFileWizardContextId; //$NON-NLS-1$
+
+ // initial value stores
+ private final String newFileExtension = Messages.WizardNewCompleteOCLFileCreationPage_fileExtension;
+
+ private final String newFileName = Messages.WizardNewCompleteOCLFileCreationPage_fileName;
+
+ private final String resourceType = Messages.WizardNewCompleteOCLFileCreationPage_file;
+
+ private final String newFileLabel = Messages.WizardNewCompleteOCLFileCreationPage_oclFileNameLabel;
+
+ // the current resource selection
+ private IStructuredSelection selection;
+
+ private Listener listener;
+
+ // widgets
+ private ResourceAndContainerGroup resourceGroup;
+
+ // Useful data
+ private URI metamodelURI;
+
+ private String metamodelNsURI;
+
+ private EPackage firstPackage = null;
+
+ /**
+ * Creates an extended new complete OCL file creation dialog. If the initial
+ * resource selection contains exactly one container resource then it will
+ * be used as the default container resource.
+ *
+ * @param parent
+ * composite widget to parent the group
+ * @param domain
+ * @param selection
+ * the current resource selection
+ * @param listener
+ * object interested in changes to the group's fields value
+ */
+ public ExtendedNewCompleteOCLFileDialog(Shell parent, EditingDomain domain,
+ IStructuredSelection selection, Listener listener) {
+ super(parent, domain);
+ this.selection = selection;
+ this.listener = listener;
+ }
+
+ public Composite createControlArea(Composite parent) {
+ initializeDialogUnits(parent);
+ // top level group
+ Composite topLevel = new Composite(parent, SWT.NONE);
+ topLevel.setLayout(new GridLayout());
+ topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
+ | GridData.HORIZONTAL_ALIGN_FILL));
+ topLevel.setFont(parent.getFont());
+ PlatformUI.getWorkbench().getHelpSystem()
+ .setHelp(topLevel, NEW_FILE_WIZARD_PAGE);
+
+ // resource and container group
+ resourceGroup = new ResourceAndContainerGroup(topLevel, listener,
+ getNewFileLabel(), getResourceType(), false,
+ SIZING_CONTAINER_GROUP_HEIGHT);
+ resourceGroup.setAllowExistingResources(false);
+ initialPopulateContainerNameField();
+ resourceGroup.setResourceExtension(getNewFileExtension());
+ resourceGroup.setResource(getNewFileName());
+
+ // load meta model area
+ createLoadMetamodelArea(topLevel);
+ return topLevel;
+ }
+
+ /**
+ * Returns the extension to display in the file name specification visual
+ * component group.
+ *
+ * @return the extension to display in the file name specification visual
+ * component group
+ */
+ public String getNewFileExtension() {
+ return newFileExtension;
+ }
+
+ /**
+ * Returns the name to display in the file name specification visual
+ * component group.
+ *
+ * @return the name to display in the file name specification visual
+ * component group
+ */
+ public String getNewFileName() {
+ return newFileName;
+ }
+
+ /**
+ * Returns the label to display in the file name specification visual
+ * component group.
+ *
+ * @return the label to display in the file name specification visual
+ * component group
+ */
+ public String getNewFileLabel() {
+ return newFileLabel;
+ }
+
+ /**
+ * Returns the resource type : one word, in lowercase, to describe the
+ * resource to the user (file, folder, project)
+ *
+ * @return the resource type to display to describe the resource to the user
+ */
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ /**
+ * @return the resource group
+ */
+ public ResourceAndContainerGroup getGroup() {
+ return resourceGroup;
+ }
+
+ /**
+ * @return The selected meta model NsURI
+ */
+ public String getMetamodelNsURI() {
+ return metamodelNsURI;
+ }
+
+ /**
+ * @param metamodelNsURI
+ * The selected metamodel nsuri
+ */
+ private void setMetamodelNsURI(String metamodelNsURI) {
+ this.metamodelNsURI = metamodelNsURI;
+ if (uriField != null) {
+ uriField.setText(metamodelNsURI);
+ }
+ }
+
+ /**
+ * @return The selected meta model uri
+ */
+ public URI getURI() {
+ return metamodelURI;
+ }
+
+ /**
+ * @param uri
+ * The selected metamodel uri
+ */
+ private void setURI(URI uri) {
+ metamodelURI = uri;
+ }
+
+ /**
+ * @return The first package of the selected meta model URI
+ */
+ public EPackage getFirstPackage() {
+ return firstPackage;
+ }
+
+ /**
+ * @param firstPackage
+ * The first package of the selected metamodel
+ */
+ private void setFirstPackage(EPackage firstPackage) {
+ this.firstPackage = firstPackage;
+ }
+
+ private void createLoadMetamodelArea(Composite parent) {
+ Label separatorLabel = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
+ {
+ GridData data = new GridData(GridData.FILL_BOTH);
+ separatorLabel.setLayoutData(data);
+ }
+
+ // meta model uri group
+ Composite metamodelURIGroup = new Composite(parent, SWT.NONE);
+ {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 0;
+ metamodelURIGroup.setLayout(layout);
+ metamodelURIGroup.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
+ metamodelURIGroup.setFont(parent.getFont());
+ }
+
+ Label metamodelURILabel = new Label(metamodelURIGroup, SWT.NONE);
+ metamodelURILabel
+ .setText(Messages.WizardNewCompleteOCLFileCreationPage_resourceURI_label);
+
+ uriField = new Text(metamodelURIGroup, SWT.BORDER);
+ {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ data.widthHint = SIZING_TEXT_FIELD_WIDTH;
+ uriField.setLayoutData(data);
+ }
+
+ setInitialUriContent();
+
+ Composite modelButtonsComposite = new Composite(parent, SWT.NONE);
+ {
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 4;
+ layout.marginWidth = 0;
+ modelButtonsComposite.setLayout(layout);
+ modelButtonsComposite.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
+ modelButtonsComposite.setFont(parent.getFont());
+ }
+
+ Button browseRegisteredPackagesButton = new Button(
+ modelButtonsComposite, SWT.PUSH);
+ browseRegisteredPackagesButton
+ .setText(Messages.WizardNewCompleteOCLFileCreationPage_browseRegisteredPackages_label);
+ prepareBrowseRegisteredPackagesButton(browseRegisteredPackagesButton);
+ {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ browseRegisteredPackagesButton.setLayoutData(data);
+ }
+
+ Button browseTargetPlatformPackagesButton = new Button(
+ modelButtonsComposite, SWT.PUSH);
+ browseTargetPlatformPackagesButton
+ .setText(Messages.WizardNewCompleteOCLFileCreationPage_browseTargetPlatformPackages_label);
+ prepareBrowseTargetPlatformPackagesButton(browseTargetPlatformPackagesButton);
+ {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ browseTargetPlatformPackagesButton.setLayoutData(data);
+ }
+
+ Button browseFileSystemButton = new Button(modelButtonsComposite,
+ SWT.PUSH);
+ browseFileSystemButton
+ .setText(Messages.WizardNewCompleteOCLFileCreationPage_browseFileSystem_label);
+ prepareBrowseFileSystemButton(browseFileSystemButton);
+
+ if (EMFPlugin.IS_RESOURCES_BUNDLE_AVAILABLE) {
+ Button browseWorkspaceButton = new Button(modelButtonsComposite,
+ SWT.PUSH);
+ {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ browseWorkspaceButton.setLayoutData(data);
+ }
+ {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ browseFileSystemButton.setLayoutData(data);
+ }
+ browseWorkspaceButton
+ .setText(Messages.WizardNewCompleteOCLFileCreationPage_browseWorkspace_label);
+ prepareBrowseWorkspaceButton(browseWorkspaceButton);
+ } else {
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ browseFileSystemButton.setLayoutData(data);
+ }
+
+ separatorLabel = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
+ {
+ GridData data = new GridData(GridData.FILL_BOTH);
+ separatorLabel.setLayoutData(data);
+ }
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void setInitialUriContent() {
+ if (selection != null && !selection.toList().isEmpty()) {
+ Iterator it = selection.iterator();
+ if (it.hasNext()) {
+ Object next = it.next();
+ if ((next instanceof IFile)) {
+ IFile file = (IFile) next;
+ URI uri = URI.createPlatformResourceURI(file.getFullPath()
+ .toString(), true);
+ uriField.setText(uri.toString());
+
+ fillContentsFromFilePath(file.getFullPath().toString());
+ setMetamodelNsURI(uri.toString());
+ }
+ }
+ }
+ }
+
+ /**
+ * Sets the initial contents of the container name entry field, based upon
+ * either a previously-specified initial value or the ability to determine
+ * such a value.
+ */
+ @SuppressWarnings("rawtypes")
+ private void initialPopulateContainerNameField() {
+ Iterator it = selection.iterator();
+ if (it.hasNext()) {
+ Object object = it.next();
+ IResource selectedResource = null;
+ if (object instanceof IResource) {
+ selectedResource = (IResource) object;
+ } else if (object instanceof IAdaptable) {
+ selectedResource = (IResource) ((IAdaptable) object)
+ .getAdapter(IResource.class);
+ }
+ if (selectedResource != null) {
+ if (selectedResource.getType() == IResource.FILE) {
+ selectedResource = selectedResource.getParent();
+ }
+ if (selectedResource.isAccessible()) {
+ resourceGroup.setContainerFullPath(selectedResource
+ .getFullPath());
+ }
+ }
+ }
+ }
+
+ public boolean isURIFieldValid() {
+ return uriField != null && uriField.getText() != "";//$NON-NLS-1$
+ }
+
+ public Collection<EPackage> getResourcePackages(Resource resource) {
+ return this.getAllPackages(resource);
+ }
+
+ /**
+ * Called to prepare the Browse File System button, this implementation adds
+ * a selection listener that creates an appropriate {@link FileDialog}.
+ */
+ @Override
+ protected void prepareBrowseFileSystemButton(Button browseFileSystemButton) {
+ browseFileSystemButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ FileDialog fileDialog = new FileDialog(getShell(), 0);
+ fileDialog.open();
+
+ String filterPath = fileDialog.getFilterPath();
+ String fileName = fileDialog.getFileName();
+ if (fileName != null) {
+ fillContentsFromFilePath(filterPath + File.separator
+ + fileName);
+ }
+ }
+ });
+ }
+
+ /**
+ * Called to prepare the Browse Workspace button, this implementation adds a
+ * selection listener that creates an appropriate
+ * {@link WorkspaceResourceDialog}.
+ */
+ @Override
+ protected void prepareBrowseWorkspaceButton(Button browseWorkspaceButton) {
+ browseWorkspaceButton.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ IFile file = null;
+
+ IFile[] files = WorkspaceResourceDialog.openFileSelection(
+ getShell(), null, null, false, null, null);
+ if (files.length != 0) {
+ file = files[0];
+ }
+
+ if (file != null) {
+ fillContentsFromWorkspacePath(file.getFullPath().toString());
+ }
+ }
+ });
+ }
+
+ @Override
+ protected void prepareBrowseTargetPlatformPackagesButton(
+ Button browseTargetPlatformPackagesButton) {
+ browseTargetPlatformPackagesButton
+ .addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ TargetPlatformPackageDialog classpathPackageDialog = new TargetPlatformPackageDialog(
+ getShell());
+ classpathPackageDialog.open();
+ Object[] result = classpathPackageDialog.getResult();
+ if (result != null) {
+ List<?> nsURIs = Arrays.asList(result);
+ fillContentsFromDevelopmentTimeVersion((String) nsURIs
+ .get(0));
+ }
+ }
+ });
+ }
+
+ @Override
+ protected void prepareBrowseRegisteredPackagesButton(
+ Button browseRegisteredPackagesButton) {
+ browseRegisteredPackagesButton
+ .addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ RegisteredPackageDialog registeredPackageDialog = new RegisteredPackageDialog(
+ getShell());
+ registeredPackageDialog.open();
+ Object[] result = registeredPackageDialog.getResult();
+ if (result != null) {
+ List<?> nsURIs = Arrays.asList(result);
+ if (registeredPackageDialog.isDevelopmentTimeVersion()) {
+ fillContentsFromDevelopmentTimeVersion((String) nsURIs
+ .get(0));
+ } else {
+ fillContentsFromRunTimeVersion((String) nsURIs
+ .get(0));
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Fills the selected metamodel URI and the first package of the selected
+ * metamodel basing on parsing a fullpath string.
+ *
+ * @param fullPath
+ */
+ public void fillContentsFromFilePath(String fullPath) {
+ setURI(URI.createFileURI(fullPath));
+
+ Resource resource = loadResource(getURI());
+ for (EPackage ePackage : getAllPackages(resource)) {
+ setFirstPackage(ePackage);
+ if (metamodelURI != null) {
+ setMetamodelNsURI(metamodelURI.toString());
+ }
+ break;
+ }
+ }
+
+ /**
+ * Fills the selected metamodel URI and the first package of the selected
+ * metamodel basing on parsing a fullpath string.
+ *
+ * @param fullPath
+ */
+ public void fillContentsFromWorkspacePath(String fullPath) {
+ setURI(URI.createFileURI(fullPath));
+
+ Resource resource = loadResource(getURI());
+ for (EPackage ePackage : getAllPackages(resource)) {
+ setFirstPackage(ePackage);
+ URI uri = URI.createPlatformResourceURI(fullPath, true);
+ setMetamodelNsURI(uri.toString());
+ break;
+ }
+ }
+
+ /**
+ * Fills the selected metamodel URI and the first package of the selected
+ * metamodel basing on parsing a list of selected URIs.
+ *
+ * @param nsURIs
+ * Platform-specific URIs
+ */
+ public void fillContentsFromDevelopmentTimeVersion(String nsURI) {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ resourceSet.getURIConverter().getURIMap()
+ .putAll(EcorePlugin.computePlatformURIMap(true));
+
+ Map<String, URI> ePackageNsURItoGenModelLocationMap = EcorePlugin
+ .getEPackageNsURIToGenModelLocationMap(true);
+ URI location = ePackageNsURItoGenModelLocationMap.get(nsURI);
+ Resource resourceToResolve = resourceSet.getResource(location, true);
+ EcoreUtil.resolveAll(resourceToResolve);
+
+ EList<Resource> resources = resourceSet.getResources();
+
+ for (Resource resource : resources) {
+ for (EPackage ePackage : getAllPackages(resource)) {
+ if (nsURI.equals(ePackage.getNsURI())) {
+ setFirstPackage(ePackage);
+ setURI(resource.getURI());
+ setMetamodelNsURI(nsURI);
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Fills the selected metamodel URI and the first package of the selected
+ * metamodel basing on the selected nsURI.
+ *
+ * @param nsURI
+ * runtime-specific URI = nsURI
+ */
+ public void fillContentsFromRunTimeVersion(String nsURI) {
+ if (nsURI.startsWith("http")) { //$NON-NLS-1$
+ String metamodelUri = getESuperPackage(nsURI);
+ setFirstPackage(EPackage.Registry.INSTANCE
+ .getEPackage(metamodelUri));
+ setMetamodelNsURI(nsURI);
+ }
+ }
+
+ /**
+ * Loads an EMF resource and returns it.
+ *
+ * @param uri
+ * The resource uri to load given as a {@link URI}
+ * @return a resource
+ */
+ private Resource loadResource(URI uri) {
+ ResourceSet set = new ResourceSetImpl();
+ set.getLoadOptions().put(XMLResource.OPTION_DEFER_ATTACHMENT, true);
+ set.getLoadOptions().put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
+ true);
+ set.setPackageRegistry(new EPackageRegistryImpl(
+ EPackage.Registry.INSTANCE));
+ return set.getResource(uri, true);
+ }
+
+ /**
+ * Gets the highest package from a meta model
+ *
+ * @param mmUri
+ * the meta model uri
+ * @return NsURI from the container package at the highest level
+ */
+ private String getESuperPackage(String mmUri) {
+
+ EPackage packageTemp = EPackage.Registry.INSTANCE.getEPackage(mmUri);
+ // Calling register on superPackage
+ if (packageTemp != null) {
+ EPackage eSuperPackage = packageTemp.getESuperPackage();
+ if (eSuperPackage != null) {
+ while (eSuperPackage != null
+ && eSuperPackage.getESuperPackage() != null) {
+ eSuperPackage = eSuperPackage.getESuperPackage();
+ }
+ return eSuperPackage.getNsURI();
+ } else {
+ return packageTemp.getNsURI();
+ }
+ }
+ return ""; //$NON-NLS-1$
+ }
+}
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerContentProvider.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerContentProvider.java
new file mode 100644
index 0000000..b06692c
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerContentProvider.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ocl.examples.ui.internal.ripoffs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * Provides content for a tree viewer that shows only containers.
+ */
+public class ContainerContentProvider implements ITreeContentProvider {
+ private boolean showClosedProjects = true;
+
+ /**
+ * Creates a new ContainerContentProvider.
+ */
+ public ContainerContentProvider() {
+ }
+
+ /**
+ * The visual part that is using this content provider is about
+ * to be disposed. Deallocate all allocated SWT resources.
+ */
+ public void dispose() {
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public Object[] getChildren(Object element) {
+ if (element instanceof IWorkspace) {
+ // check if closed projects should be shown
+ IProject[] allProjects = ((IWorkspace) element).getRoot()
+ .getProjects();
+ if (showClosedProjects) {
+ return allProjects;
+ }
+
+ ArrayList accessibleProjects = new ArrayList();
+ for (int i = 0; i < allProjects.length; i++) {
+ if (allProjects[i].isOpen()) {
+ accessibleProjects.add(allProjects[i]);
+ }
+ }
+ return accessibleProjects.toArray();
+ } else if (element instanceof IContainer) {
+ IContainer container = (IContainer) element;
+ if (container.isAccessible()) {
+ try {
+ List children = new ArrayList();
+ IResource[] members = container.members();
+ for (int i = 0; i < members.length; i++) {
+ if (members[i].getType() != IResource.FILE) {
+ children.add(members[i]);
+ }
+ }
+ return children.toArray();
+ } catch (CoreException e) {
+ // this should never happen because we call #isAccessible before invoking #members
+ }
+ }
+ }
+ return new Object[0];
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements(Object element) {
+ return getChildren(element);
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public Object getParent(Object element) {
+ if (element instanceof IResource) {
+ return ((IResource) element).getParent();
+ }
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ /*
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ /**
+ * Specify whether or not to show closed projects in the tree
+ * viewer. Default is to show closed projects.
+ *
+ * @param show boolean if false, do not show closed projects in the tree
+ */
+ public void showClosedProjects(boolean show) {
+ showClosedProjects = show;
+ }
+
+}
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerSelectionGroup.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerSelectionGroup.java
new file mode 100644
index 0000000..f69c71d
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ContainerSelectionGroup.java
@@ -0,0 +1,356 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Igor Fedorenko <igorfie@yahoo.com> -
+ * Fix for Bug 136921 [IDE] New File dialog locks for 20 seconds
+ *******************************************************************************/
+package org.eclipse.ocl.examples.ui.internal.ripoffs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.util.BidiUtils;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.ocl.examples.ui.messages.Messages;
+import org.eclipse.osgi.util.TextProcessor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.part.DrillDownComposite;
+
+/**
+ * Workbench-level composite for choosing a container.
+ */
+public class ContainerSelectionGroup extends Composite {
+ // The listener to notify of events
+ private Listener listener;
+
+ // Enable user to type in new container name
+ private boolean allowNewContainerName = true;
+
+ // show all projects by default
+ private boolean showClosedProjects = true;
+
+ // Last selection made by user
+ private IContainer selectedContainer;
+
+ // handle on parts
+ private Text containerNameField;
+
+ TreeViewer treeViewer;
+
+ // the message to display at the top of this dialog
+ private static final String DEFAULT_MSG_NEW_ALLOWED = Messages.WizardNewCompleteOCLFileCreationPage_ContainerGroup_message;
+
+ private static final String DEFAULT_MSG_SELECT_ONLY = Messages.WizardNewCompleteOCLFileCreationPage_ContainerGroup_selectFolder;
+
+ // sizing constants
+ private static final int SIZING_SELECTION_PANE_WIDTH = 320;
+
+ private static final int SIZING_SELECTION_PANE_HEIGHT = 300;
+
+ /**
+ * Creates a new instance of the widget.
+ *
+ * @param parent
+ * The parent widget of the group.
+ * @param listener
+ * A listener to forward events to. Can be null if no listener is
+ * required.
+ * @param allowNewContainerName
+ * Enable the user to type in a new container name instead of
+ * just selecting from the existing ones.
+ */
+ public ContainerSelectionGroup(Composite parent, Listener listener,
+ boolean allowNewContainerName) {
+ this(parent, listener, allowNewContainerName, null);
+ }
+
+ /**
+ * Creates a new instance of the widget.
+ *
+ * @param parent
+ * The parent widget of the group.
+ * @param listener
+ * A listener to forward events to. Can be null if no listener is
+ * required.
+ * @param allowNewContainerName
+ * Enable the user to type in a new container name instead of
+ * just selecting from the existing ones.
+ * @param message
+ * The text to present to the user.
+ */
+ public ContainerSelectionGroup(Composite parent, Listener listener,
+ boolean allowNewContainerName, String message) {
+ this(parent, listener, allowNewContainerName, message, true);
+ }
+
+ /**
+ * Creates a new instance of the widget.
+ *
+ * @param parent
+ * The parent widget of the group.
+ * @param listener
+ * A listener to forward events to. Can be null if no listener is
+ * required.
+ * @param allowNewContainerName
+ * Enable the user to type in a new container name instead of
+ * just selecting from the existing ones.
+ * @param message
+ * The text to present to the user.
+ * @param showClosedProjects
+ * Whether or not to show closed projects.
+ */
+ public ContainerSelectionGroup(Composite parent, Listener listener,
+ boolean allowNewContainerName, String message,
+ boolean showClosedProjects) {
+ this(parent, listener, allowNewContainerName, message,
+ showClosedProjects, SIZING_SELECTION_PANE_HEIGHT,
+ SIZING_SELECTION_PANE_WIDTH);
+ }
+
+ /**
+ * Creates a new instance of the widget.
+ *
+ * @param parent
+ * The parent widget of the group.
+ * @param listener
+ * A listener to forward events to. Can be null if no listener is
+ * required.
+ * @param allowNewContainerName
+ * Enable the user to type in a new container name instead of
+ * just selecting from the existing ones.
+ * @param message
+ * The text to present to the user.
+ * @param showClosedProjects
+ * Whether or not to show closed projects.
+ * @param heightHint
+ * height hint for the drill down composite
+ * @param widthHint
+ * width hint for the drill down composite
+ */
+ public ContainerSelectionGroup(Composite parent, Listener listener,
+ boolean allowNewContainerName, String message,
+ boolean showClosedProjects, int heightHint, int widthHint) {
+ super(parent, SWT.NONE);
+ this.listener = listener;
+ this.allowNewContainerName = allowNewContainerName;
+ this.showClosedProjects = showClosedProjects;
+ if (message != null) {
+ createContents(message, heightHint, widthHint);
+ } else if (allowNewContainerName) {
+ createContents(DEFAULT_MSG_NEW_ALLOWED, heightHint, widthHint);
+ } else {
+ createContents(DEFAULT_MSG_SELECT_ONLY, heightHint, widthHint);
+ }
+ }
+
+ /**
+ * The container selection has changed in the tree view. Update the
+ * container name field value and notify all listeners.
+ *
+ * @param container
+ * The container that changed
+ */
+ public void containerSelectionChanged(IContainer container) {
+ selectedContainer = container;
+
+ if (allowNewContainerName) {
+ if (container == null) {
+ containerNameField.setText("");//$NON-NLS-1$
+ } else {
+ String text = TextProcessor.process(container.getFullPath()
+ .makeRelative().toString());
+ containerNameField.setText(text);
+ containerNameField.setToolTipText(text);
+ }
+ }
+
+ // fire an event so the parent can update its controls
+ if (listener != null) {
+ Event changeEvent = new Event();
+ changeEvent.type = SWT.Selection;
+ changeEvent.widget = this;
+ listener.handleEvent(changeEvent);
+ }
+ }
+
+ /**
+ * Creates the contents of the composite.
+ *
+ * @param message
+ */
+ public void createContents(String message) {
+ createContents(message, SIZING_SELECTION_PANE_HEIGHT,
+ SIZING_SELECTION_PANE_WIDTH);
+ }
+
+ /**
+ * Creates the contents of the composite.
+ *
+ * @param message
+ * @param heightHint
+ * @param widthHint
+ */
+ public void createContents(String message, int heightHint, int widthHint) {
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ setLayout(layout);
+ setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ Label label = new Label(this, SWT.WRAP);
+ label.setText(message);
+ label.setFont(this.getFont());
+
+ if (allowNewContainerName) {
+ containerNameField = new Text(this, SWT.SINGLE | SWT.BORDER);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.widthHint = widthHint;
+ containerNameField.setLayoutData(gd);
+ containerNameField.addListener(SWT.Modify, listener);
+ containerNameField.setFont(this.getFont());
+ BidiUtils.applyBidiProcessing(containerNameField, StructuredTextTypeHandlerFactory.FILE);
+ } else {
+ // filler...
+ new Label(this, SWT.NONE);
+ }
+
+ createTreeViewer(heightHint);
+ Dialog.applyDialogFont(this);
+ }
+
+ /**
+ * Returns a new drill down viewer for this dialog.
+ *
+ * @param heightHint
+ * height hint for the drill down composite
+ */
+ protected void createTreeViewer(int heightHint) {
+ // Create drill down.
+ DrillDownComposite drillDown = new DrillDownComposite(this, SWT.BORDER);
+ GridData spec = new GridData(SWT.FILL, SWT.FILL, true, true);
+ spec.widthHint = SIZING_SELECTION_PANE_WIDTH;
+ spec.heightHint = heightHint;
+ drillDown.setLayoutData(spec);
+
+ // Create tree viewer inside drill down.
+ treeViewer = new TreeViewer(drillDown, SWT.NONE);
+ drillDown.setChildTree(treeViewer);
+ ContainerContentProvider cp = new ContainerContentProvider();
+ cp.showClosedProjects(showClosedProjects);
+ treeViewer.setContentProvider(cp);
+ treeViewer.setLabelProvider(WorkbenchLabelProvider
+ .getDecoratingWorkbenchLabelProvider());
+ treeViewer.setComparator(new ViewerComparator());
+ treeViewer.setUseHashlookup(true);
+ treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+ containerSelectionChanged((IContainer) selection
+ .getFirstElement()); // allow null
+ }
+ });
+ treeViewer.addDoubleClickListener(new IDoubleClickListener() {
+ public void doubleClick(DoubleClickEvent event) {
+ ISelection selection = event.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ Object item = ((IStructuredSelection) selection)
+ .getFirstElement();
+ if (item == null) {
+ return;
+ }
+ if (treeViewer.getExpandedState(item)) {
+ treeViewer.collapseToLevel(item, 1);
+ } else {
+ treeViewer.expandToLevel(item, 1);
+ }
+ }
+ }
+ });
+
+ // This has to be done after the viewer has been laid out
+ treeViewer.setInput(ResourcesPlugin.getWorkspace());
+ }
+
+ /**
+ * Returns the currently entered container name. Null if the field is empty.
+ * Note that the container may not exist yet if the user entered a new
+ * container name in the field.
+ *
+ * @return IPath
+ */
+ public IPath getContainerFullPath() {
+ if (allowNewContainerName) {
+ String pathName = containerNameField.getText();
+ if (pathName == null || pathName.length() < 1) {
+ return null;
+ }
+ // The user may not have made this absolute so do it for them
+ return (new Path(TextProcessor.deprocess(pathName))).makeAbsolute();
+
+ }
+ if (selectedContainer == null)
+ return null;
+ return selectedContainer.getFullPath();
+
+ }
+
+ /**
+ * Gives focus to one of the widgets in the group, as determined by the
+ * group.
+ */
+ public void setInitialFocus() {
+ if (allowNewContainerName) {
+ containerNameField.setFocus();
+ } else {
+ treeViewer.getTree().setFocus();
+ }
+ }
+
+ /**
+ * Sets the selected existing container.
+ *
+ * @param container
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ public void setSelectedContainer(IContainer container) {
+ selectedContainer = container;
+
+ // expand to and select the specified container
+ List itemsToExpand = new ArrayList();
+ IContainer parent = container.getParent();
+ while (parent != null) {
+ itemsToExpand.add(0, parent);
+ parent = parent.getParent();
+ }
+ treeViewer.setExpandedElements(itemsToExpand.toArray());
+ treeViewer.setSelection(new StructuredSelection(container), true);
+ }
+}
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ResourceAndContainerGroup.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ResourceAndContainerGroup.java
new file mode 100644
index 0000000..c424bc0
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/internal/ripoffs/ResourceAndContainerGroup.java
@@ -0,0 +1,521 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Alexander Fedorov <Alexander.Fedorov@borland.com>
+ * - Bug 172000 [Wizards] WizardNewFileCreationPage should support overwriting existing resources
+ *******************************************************************************/
+package org.eclipse.ocl.examples.ui.internal.ripoffs;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.equinox.bidi.StructuredTextTypeHandlerFactory;
+import org.eclipse.jface.util.BidiUtils;
+import org.eclipse.ocl.examples.ui.messages.Messages;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * Workbench-level composite for resource and container specification by the
+ * user. Services such as field validation are performed by the group. The group
+ * can be configured to accept existing resources, or only new resources.
+ */
+public class ResourceAndContainerGroup implements Listener {
+ // problem identifiers
+
+ /**
+ * Constant for no problem.
+ */
+ public static final int PROBLEM_NONE = 0;
+ /**
+ * Constant for empty resource.
+ */
+ public static final int PROBLEM_RESOURCE_EMPTY = 1;
+
+ /**
+ * Constant for resource already exists.
+ */
+ public static final int PROBLEM_RESOURCE_EXIST = 2;
+
+ /**
+ * Constant for invalid path.
+ */
+ public static final int PROBLEM_PATH_INVALID = 4;
+
+ /**
+ * Constant for empty container.
+ */
+ public static final int PROBLEM_CONTAINER_EMPTY = 5;
+
+ /**
+ * Constant for project does not exist.
+ */
+ public static final int PROBLEM_PROJECT_DOES_NOT_EXIST = 6;
+
+ /**
+ * Constant for invalid name.
+ */
+ public static final int PROBLEM_NAME_INVALID = 7;
+
+ /**
+ * Constant for path already occupied.
+ */
+ public static final int PROBLEM_PATH_OCCUPIED = 8;
+
+ // the client to notify of changes
+ private Listener client;
+
+ // whether to allow existing resources
+ private boolean allowExistingResources = false;
+
+ // resource type (file, folder, project)
+ private String resourceType = Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_resource;
+
+ // show closed projects in the tree, by default
+ private boolean showClosedProjects = true;
+
+ // problem indicator
+ private String problemMessage = "";//$NON-NLS-1$
+
+ private int problemType = PROBLEM_NONE;
+
+ // widgets
+ private ContainerSelectionGroup containerGroup;
+
+ private Text resourceNameField;
+
+ /**
+ * The resource extension for the resource name field.
+ *
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @since 3.3
+ */
+ private String resourceExtension;
+
+ // constants
+ private static final int SIZING_TEXT_FIELD_WIDTH = 250;
+
+ /**
+ * Create an instance of the group to allow the user to enter/select a
+ * container and specify a resource name.
+ *
+ * @param parent
+ * composite widget to parent the group
+ * @param client
+ * object interested in changes to the group's fields value
+ * @param resourceFieldLabel
+ * label to use in front of the resource name field
+ * @param resourceType
+ * one word, in lowercase, to describe the resource to the user
+ * (file, folder, project)
+ * @param showClosedProjects
+ * whether or not to show closed projects
+ * @param heightHint
+ * height hint for the container selection widget group
+ */
+ public ResourceAndContainerGroup(Composite parent, Listener client,
+ String resourceFieldLabel, String resourceType,
+ boolean showClosedProjects, int heightHint) {
+ super();
+ this.resourceType = resourceType;
+ this.showClosedProjects = showClosedProjects;
+ createContents(parent, resourceFieldLabel, heightHint);
+ this.client = client;
+ }
+
+ /**
+ * Returns a boolean indicating whether all controls in this group contain
+ * valid values.
+ *
+ * @return boolean
+ */
+ public boolean areAllValuesValid() {
+ return problemType == PROBLEM_NONE;
+ }
+
+ /**
+ * Creates this object's visual components.
+ *
+ * @param parent
+ * org.eclipse.swt.widgets.Composite
+ * @param heightHint
+ * height hint for the container selection widget group
+ */
+ protected void createContents(Composite parent, String resourceLabelString,
+ int heightHint) {
+
+ Font font = parent.getFont();
+ // server name group
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ layout.marginHeight = 0;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ composite.setFont(font);
+
+ // container group
+ if (heightHint == SWT.DEFAULT) {
+ containerGroup = new ContainerSelectionGroup(composite, this, true,
+ null, showClosedProjects);
+ } else {
+ containerGroup = new ContainerSelectionGroup(composite, this, true,
+ null, showClosedProjects, heightHint,
+ SIZING_TEXT_FIELD_WIDTH);
+ }
+
+ // resource name group
+ Composite nameGroup = new Composite(composite, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginWidth = 0;
+ nameGroup.setLayout(layout);
+ nameGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL));
+ nameGroup.setFont(font);
+
+ Label label = new Label(nameGroup, SWT.NONE);
+ label.setText(resourceLabelString);
+ label.setFont(font);
+
+ // resource name entry field
+ resourceNameField = new Text(nameGroup, SWT.BORDER);
+ resourceNameField.addListener(SWT.Modify, this);
+ resourceNameField.addFocusListener(new FocusAdapter() {
+ public void focusLost(FocusEvent e) {
+ handleResourceNameFocusLostEvent();
+ }
+ });
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL
+ | GridData.GRAB_HORIZONTAL);
+ data.widthHint = SIZING_TEXT_FIELD_WIDTH;
+ resourceNameField.setLayoutData(data);
+ resourceNameField.setFont(font);
+ BidiUtils.applyBidiProcessing(resourceNameField, StructuredTextTypeHandlerFactory.FILE);
+ validateControls();
+ }
+
+ /**
+ * Returns the path of the currently selected container or null if no
+ * container has been selected. Note that the container may not exist yet if
+ * the user entered a new container name in the field.
+ *
+ * @return The path of the container, or <code>null</code>
+ */
+ public IPath getContainerFullPath() {
+ return containerGroup.getContainerFullPath();
+ }
+
+ /**
+ * Returns an error message indicating the current problem with the value of
+ * a control in the group, or an empty message if all controls in the group
+ * contain valid values.
+ *
+ * @return java.lang.String
+ */
+ public String getProblemMessage() {
+ return problemMessage;
+ }
+
+ /**
+ * Returns the type of problem with the value of a control in the group.
+ *
+ * @return one of the PROBLEM_* constants
+ */
+ public int getProblemType() {
+ return problemType;
+ }
+
+ /**
+ * Returns a string that is the name of the chosen resource, or an empty
+ * string if no resource has been entered. <br>
+ * <br>
+ * The name will include the resource extension if the preconditions are
+ * met.
+ *
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ *
+ * @return The resource name
+ * @since 3.3
+ */
+ public String getResource() {
+ String resource = resourceNameField.getText();
+ if (useResourceExtension()) {
+ return resource + '.' + resourceExtension;
+ }
+ return resource;
+ }
+
+ /**
+ * Determines whether the resource extension should be added to the resource
+ * name field. <br>
+ * <br>
+ *
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @return <code>true</code> if the preconditions are met; otherwise,
+ * <code>false</code>.
+ * @since 3.3
+ */
+ private boolean useResourceExtension() {
+ String resource = resourceNameField.getText();
+ if ((resourceExtension != null) && (resourceExtension.length() > 0)
+ && (resource.length() > 0)
+ && (resource.endsWith('.' + resourceExtension) == false)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Handle the focus lost event from the resource name field. <br>
+ * Adds the resource extension to the resource name field when it loses
+ * focus (if the preconditions are met).
+ *
+ * @see ResourceAndContainerGroup#setResourceExtension(String)
+ * @since 3.3
+ */
+ private void handleResourceNameFocusLostEvent() {
+ if (useResourceExtension()) {
+ setResource(resourceNameField.getText() + '.' + resourceExtension);
+ }
+ }
+
+ /**
+ * Handles events for all controls in the group.
+ *
+ * @param e
+ * org.eclipse.swt.widgets.Event
+ */
+ public void handleEvent(Event e) {
+ validateControls();
+ if (client != null) {
+ client.handleEvent(e);
+ }
+ }
+
+ /**
+ * Sets the flag indicating whether existing resources are permitted.
+ * @param value
+ */
+ public void setAllowExistingResources(boolean value) {
+ allowExistingResources = value;
+ }
+
+ /**
+ * Sets the value of this page's container.
+ *
+ * @param path
+ * Full path to the container.
+ */
+ public void setContainerFullPath(IPath path) {
+ IResource initial = ResourcesPlugin.getWorkspace().getRoot()
+ .findMember(path);
+ if (initial != null) {
+ if (!(initial instanceof IContainer)) {
+ initial = initial.getParent();
+ }
+ containerGroup.setSelectedContainer((IContainer) initial);
+ }
+ validateControls();
+ }
+
+ /**
+ * Gives focus to the resource name field and selects its contents
+ */
+ public void setFocus() {
+ // select the whole resource name.
+ resourceNameField.setSelection(0, resourceNameField.getText().length());
+ resourceNameField.setFocus();
+ }
+
+ /**
+ * Sets the value of this page's resource name.
+ *
+ * @param value
+ * new value
+ */
+ public void setResource(String value) {
+ resourceNameField.setText(value);
+ validateControls();
+ }
+
+ /**
+ * Set the only file extension allowed for the resource name field. <br>
+ * <br>
+ * If a resource extension is specified, then it will always be appended
+ * with a '.' to the text from the resource name field for validation when
+ * the following conditions are met: <br>
+ * <br>
+ * (1) Resource extension length is greater than 0 <br>
+ * (2) Resource name field text length is greater than 0 <br>
+ * (3) Resource name field text does not already end with a '.' and the
+ * resource extension specified (case sensitive) <br>
+ * <br>
+ * The resource extension will not be reflected in the actual resource name
+ * field until the resource name field loses focus.
+ *
+ * @param value
+ * The resource extension without the '.' prefix (e.g. 'java',
+ * 'xml')
+ * @since 3.3
+ */
+ public void setResourceExtension(String value) {
+ resourceExtension = value;
+ validateControls();
+ }
+
+ /**
+ * Returns a <code>boolean</code> indicating whether a container name
+ * represents a valid container resource in the workbench. An error message
+ * is stored for future reference if the name does not represent a valid
+ * container.
+ *
+ * @return <code>boolean</code> indicating validity of the container name
+ */
+ protected boolean validateContainer() {
+ IPath path = containerGroup.getContainerFullPath();
+ if (path == null) {
+ problemType = PROBLEM_CONTAINER_EMPTY;
+ problemMessage = Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_folderEmpty;
+ return false;
+ }
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ String projectName = path.segment(0);
+ if (projectName == null
+ || !workspace.getRoot().getProject(projectName).exists()) {
+ problemType = PROBLEM_PROJECT_DOES_NOT_EXIST;
+ problemMessage = Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_noProject;
+ return false;
+ }
+ // path is invalid if any prefix is occupied by a file
+ IWorkspaceRoot root = workspace.getRoot();
+ while (path.segmentCount() > 1) {
+ if (root.getFile(path).exists()) {
+ problemType = PROBLEM_PATH_OCCUPIED;
+ problemMessage = NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_pathOccupied, path
+ .makeRelative());
+ return false;
+ }
+ path = path.removeLastSegments(1);
+ }
+ return true;
+ }
+
+ /**
+ * Validates the values for each of the group's controls. If an invalid
+ * value is found then a descriptive error message is stored for later
+ * reference. Returns a boolean indicating the validity of all of the
+ * controls in the group.
+ */
+ protected boolean validateControls() {
+ // don't attempt to validate controls until they have been created
+ if (containerGroup == null) {
+ return false;
+ }
+ problemType = PROBLEM_NONE;
+ problemMessage = "";//$NON-NLS-1$
+
+ if (!validateContainer() || !validateResourceName()) {
+ return false;
+ }
+
+ IPath path = containerGroup.getContainerFullPath()
+ .append(getResource());
+ return validateFullResourcePath(path);
+ }
+
+ /**
+ * Returns a <code>boolean</code> indicating whether the specified
+ * resource path represents a valid new resource in the workbench. An error
+ * message is stored for future reference if the path does not represent a
+ * valid new resource path.
+ *
+ * @param resourcePath
+ * the path to validate
+ * @return <code>boolean</code> indicating validity of the resource path
+ */
+ protected boolean validateFullResourcePath(IPath resourcePath) {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+
+ IStatus result = workspace.validatePath(resourcePath.toString(),
+ IResource.FOLDER);
+ if (!result.isOK()) {
+ problemType = PROBLEM_PATH_INVALID;
+ problemMessage = result.getMessage();
+ return false;
+ }
+
+ if (!allowExistingResources
+ && (workspace.getRoot().getFolder(resourcePath).exists() || workspace
+ .getRoot().getFile(resourcePath).exists())) {
+ problemType = PROBLEM_RESOURCE_EXIST;
+ problemMessage = NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_nameExists,
+ getResource());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns a <code>boolean</code> indicating whether the resource name
+ * rep- resents a valid resource name in the workbench. An error message is
+ * stored for future reference if the name does not represent a valid
+ * resource name.
+ *
+ * @return <code>boolean</code> indicating validity of the resource name
+ */
+ protected boolean validateResourceName() {
+ String resourceName = getResource();
+
+ if (resourceName.length() == 0) {
+ problemType = PROBLEM_RESOURCE_EMPTY;
+ problemMessage = NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_emptyName, resourceType);
+ return false;
+ }
+
+ if (!Path.ROOT.isValidPath(resourceName)) {
+ problemType = PROBLEM_NAME_INVALID;
+ problemMessage = NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_ResourceGroup_invalidFilename,
+ resourceName);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Returns the flag indicating whether existing resources are permitted.
+ *
+ * @return The allow existing resources flag.
+ * @see ResourceAndContainerGroup#setAllowExistingResources(boolean)
+ * @since 3.4
+ */
+ public boolean getAllowExistingResources() {
+ return allowExistingResources;
+ }
+
+}
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.java
new file mode 100644
index 0000000..2598ea0
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.java
@@ -0,0 +1,69 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - Initial API and implementation
+ * </copyright>
+ *
+ * $Id$
+ */
+
+package org.eclipse.ocl.examples.ui.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * An accessor class for externalized strings.
+ */
+public class Messages
+{
+ static {
+ NLS.initializeMessages(Messages.class.getName(), Messages.class);
+ }
+
+ public static String WizardNewCompleteOCLFileCreationPage_newCompleteOCLFile;
+ public static String WizardNewCompleteOCLFileCreationPage_completeOCLFile;
+ public static String WizardNewCompleteOCLFileCreationPage_fileExtension;
+ public static String WizardNewCompleteOCLFileCreationPage_fileName;
+ public static String WizardNewCompleteOCLFileCreationPage_file;
+ public static String WizardNewCompleteOCLFileCreationPage_createCompleteOCLFileBasedOnModel;
+ public static String WizardNewCompleteOCLFileCreationPage_oclFileNameLabel;
+ public static String WizardNewCompleteOCLFileCreationPage_errorTitle;
+ public static String WizardNewCompleteOCLFileCreationPage_internalErrorTitle;
+ public static String WizardNewCompleteOCLFileCreationPage_internalErrorMessage;
+ public static String WizardNewCompleteOCLFileCreationPage_nameExists;
+ public static String WizardNewCompleteOCLFileCreationPage_resourceWillBeFilteredWarning;
+ public static String WizardNewCompleteOCLFileCreationPage_browseRegisteredPackages_label;
+ public static String WizardNewCompleteOCLFileCreationPage_browseTargetPlatformPackages_label;
+ public static String WizardNewCompleteOCLFileCreationPage_selectRegisteredPackageURI;
+ public static String WizardNewCompleteOCLFileCreationPage_packageSelection_label;
+ public static String WizardNewCompleteOCLFileCreationPage_developmentTimeVersion_label;
+ public static String WizardNewCompleteOCLFileCreationPage_runtimeVersion_label;
+ public static String WizardNewCompleteOCLFileCreationPage_runtimePackageDetail_message;
+ public static String WizardNewCompleteOCLFileCreationPage_information_title;
+ public static String WizardNewCompleteOCLFileCreationPage_runtimePackageHeader_message;
+ public static String WizardNewCompleteOCLFileCreationPage_resourceURI_label;
+ public static String WizardNewCompleteOCLFileCreationPage_resourceURIs_label;
+ public static String WizardNewCompleteOCLFileCreationPage_browseFileSystem_label;
+ public static String WizardNewCompleteOCLFileCreationPage_browseWorkspace_label;
+
+ public static String WizardNewCompleteOCLFileCreationPage_newFileWizardContextId;
+
+ // source IDEWorkbenchMessages
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_resource;
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_nameExists;
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_folderEmpty;
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_noProject;
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_emptyName;
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_invalidFilename;
+ public static String WizardNewCompleteOCLFileCreationPage_ResourceGroup_pathOccupied;
+
+ public static String WizardNewCompleteOCLFileCreationPage_ContainerGroup_message;
+ public static String WizardNewCompleteOCLFileCreationPage_ContainerGroup_selectFolder;
+} \ No newline at end of file
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.properties b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.properties
new file mode 100644
index 0000000..dc3ef1a
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/messages/Messages.properties
@@ -0,0 +1,51 @@
+###############################################################################
+# Copyright (c) 2013 Obeo and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Obeo - initial API and implementation
+# $Id$
+###############################################################################
+
+WizardNewCompleteOCLFileCreationPage_newCompleteOCLFile=New Complete OCL File
+WizardNewCompleteOCLFileCreationPage_completeOCLFile=Complete OCL File
+WizardNewCompleteOCLFileCreationPage_fileExtension=ocl
+WizardNewCompleteOCLFileCreationPage_fileName=NewOCLFile
+WizardNewCompleteOCLFileCreationPage_file=file
+WizardNewCompleteOCLFileCreationPage_createCompleteOCLFileBasedOnModel=Creates a new complete OCL file based on a given model.
+WizardNewCompleteOCLFileCreationPage_oclFileNameLabel=OCL file name:
+WizardNewCompleteOCLFileCreationPage_errorTitle = Creation problems
+WizardNewCompleteOCLFileCreationPage_internalErrorTitle = Creation problems
+WizardNewCompleteOCLFileCreationPage_internalErrorMessage = Internal error: {0}
+WizardNewCompleteOCLFileCreationPage_nameExists = ''{0}'' already exists.
+WizardNewCompleteOCLFileCreationPage_resourceWillBeFilteredWarning=This file is hidden in the workspace due to resource filters. To override existing resource filters, a linked file can be created instead.
+WizardNewCompleteOCLFileCreationPage_browseRegisteredPackages_label = Browse &Registered Packages...
+WizardNewCompleteOCLFileCreationPage_browseTargetPlatformPackages_label = Browse &Target Platform Packages...
+WizardNewCompleteOCLFileCreationPage_selectRegisteredPackageURI = &Select a registered package URI:
+WizardNewCompleteOCLFileCreationPage_packageSelection_label = Package Selection
+WizardNewCompleteOCLFileCreationPage_developmentTimeVersion_label = &Development Time Version
+WizardNewCompleteOCLFileCreationPage_runtimeVersion_label = &Runtime Version
+WizardNewCompleteOCLFileCreationPage_runtimePackageDetail_message = Runtime packages are registered in the package registry and are not loaded as resources so while the package contents will be available for setting properties, they will not be displayed directly. Click details to see the list of successfully loaded runtime packages
+WizardNewCompleteOCLFileCreationPage_information_title = Information
+WizardNewCompleteOCLFileCreationPage_runtimePackageHeader_message = Runtime packages are not displayed in the editor
+WizardNewCompleteOCLFileCreationPage_resourceURI_label = Metamodel &URI:
+WizardNewCompleteOCLFileCreationPage_resourceURIs_label = Metamodel &URIs:
+WizardNewCompleteOCLFileCreationPage_browseFileSystem_label = Browse &File System...
+WizardNewCompleteOCLFileCreationPage_browseWorkspace_label = Browse &Workspace...
+
+WizardNewCompleteOCLFileCreationPage_newFileWizardContextId =new_file_wizard_page_context
+
+# source IDEWorkbenchMessages
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_resource = resource
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_nameExists = ''{0}'' already exists.
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_folderEmpty = No folder specified.
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_noProject = The specified project does not exist.
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_emptyName = The ''{0}'' name is empty.
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_invalidFilename = ''{0}'' is not a valid file name.
+WizardNewCompleteOCLFileCreationPage_ResourceGroup_pathOccupied = A file already exists at that location: {0}
+
+WizardNewCompleteOCLFileCreationPage_ContainerGroup_message = &Enter or select the parent folder:
+WizardNewCompleteOCLFileCreationPage_ContainerGroup_selectFolder = Select the folder: \ No newline at end of file
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreation.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreation.java
new file mode 100644
index 0000000..4f733de
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreation.java
@@ -0,0 +1,88 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.ui.wizards;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ocl.common.ui.internal.Activator;
+import org.eclipse.ocl.examples.ui.messages.Messages;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Wizard allowing the user to create a new OCL rule file.
+ */
+public class WizardNewCompleteOCLFileCreation
+ extends Wizard
+ implements INewWizard {
+
+ /** The only page contributing to the wizard */
+ protected WizardNewCompleteOCLFileCreationPage page;
+
+ /**
+ * Constructor
+ */
+ public WizardNewCompleteOCLFileCreation() {
+ super();
+ setWindowTitle(Messages.WizardNewCompleteOCLFileCreationPage_newCompleteOCLFile);
+ setDefaultPageImageDescriptor(Activator
+ .getImageDescriptor("icons/OCLModelFile.gif"));
+ }
+
+ /**
+ * Performs finish action of this wizard.
+ *
+ * @see org.eclipse.jface.wizard.Wizard#performFinish()
+ */
+ @Override
+ public boolean performFinish() {
+ final IFile file = page.createNewFile();
+
+ try {
+ openCreatedFile(file);
+ } catch (PartInitException e) {
+ Activator.log(e);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Opens file in the Editor
+ * @param the file to open
+ * @throws PartInitException
+ */
+ private void openCreatedFile(IFile file)
+ throws PartInitException {
+ IWorkbenchPage currentPage = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+ IDE.openEditor(currentPage, file, true);
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+ * org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ page = new WizardNewCompleteOCLFileCreationPage(selection);
+ addPage(page);
+ }
+} \ No newline at end of file
diff --git a/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreationPage.java b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreationPage.java
new file mode 100644
index 0000000..8258760
--- /dev/null
+++ b/examples/org.eclipse.ocl.examples.ui/src/org/eclipse/ocl/examples/ui/wizards/WizardNewCompleteOCLFileCreationPage.java
@@ -0,0 +1,378 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.ui.wizards;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.ocl.common.ui.internal.Activator;
+import org.eclipse.ocl.examples.ui.dialogs.ExtendedNewCompleteOCLFileDialog;
+import org.eclipse.ocl.examples.ui.internal.ripoffs.ResourceAndContainerGroup;
+import org.eclipse.ocl.examples.ui.messages.Messages;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.ui.ide.undo.CreateFileOperation;
+import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
+
+/**
+ * Wizard page allowing creation of OCL rule files in the workspace.
+ */
+public class WizardNewCompleteOCLFileCreationPage
+ extends WizardPage
+ implements Listener {
+
+ // the current resource selection
+ private IStructuredSelection currentSelection;
+
+ // cache of newly-created file
+ private IFile newFile;
+
+ private ExtendedNewCompleteOCLFileDialog dialog;
+
+ /**
+ * Creates a new complete OCL file creation wizard page. If the initial
+ * resource selection contains exactly one container resource then it will
+ * be used as the default container resource.
+ *
+ * @param selection
+ * the current resource selection
+ */
+ public WizardNewCompleteOCLFileCreationPage(IStructuredSelection selection) {
+ super("page"); //$NON-NLS-1$
+ setPageComplete(false);
+ setTitle(Messages.WizardNewCompleteOCLFileCreationPage_completeOCLFile);
+ setDescription(Messages.WizardNewCompleteOCLFileCreationPage_createCompleteOCLFileBasedOnModel);
+ this.currentSelection = selection;
+ }
+
+ /**
+ * Creates a file resource handle for the file with the given workspace
+ * path. This method does not create the file resource; this is the
+ * responsibility of <code>createNewFile</code>.
+ *
+ * @param filePath
+ * the path of the file resource to create a handle for
+ * @return the new complete OCL file resource handle
+ * @see #createFile
+ */
+ protected IFile createFileHandle(IPath filePath) {
+ return Activator.getPluginWorkspace().getRoot().getFile(filePath);
+ }
+
+ /**
+ * Creates a new complete OCL file resource in the selected container and
+ * with the selected name. Creates any missing resource containers along the
+ * path; does nothing if the container resources already exist.
+ * <p>
+ * In normal usage, this method is invoked after the user has pressed Finish
+ * on the wizard; the enablement of the Finish button implies that all
+ * controls on on this page currently contain valid values.
+ * </p>
+ * <p>
+ * Note that this page caches the new complete OCL file once it has been
+ * successfully created; subsequent invocations of this method will answer
+ * the same file resource without attempting to create it again.
+ * </p>
+ * <p>
+ * This method should be called within a workspace modify operation since it
+ * creates resources.
+ * </p>
+ *
+ * @return the created file resource, or <code>null</code> if the file was
+ * not created
+ */
+ public IFile createNewFile() {
+ if (newFile != null) {
+ return newFile;
+ }
+
+ // create the new complete OCL file and cache it if successful
+ IPath newFilePath = getNewFilePath();
+
+ final IFile newFileHandle = createFileHandle(newFilePath);
+ newFile = newFileHandle;
+
+ final InputStream initialContents = getInitialContents();
+
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) {
+ CreateFileOperation op = new CreateFileOperation(
+ newFileHandle,
+ null,
+ initialContents,
+ Messages.WizardNewCompleteOCLFileCreationPage_newCompleteOCLFile);
+ try {
+ op.execute(monitor,
+ WorkspaceUndoUtil.getUIInfoAdapter(getShell()));
+ } catch (final ExecutionException e) {
+ getContainer().getShell().getDisplay()
+ .syncExec(new Runnable() {
+
+ public void run() {
+ if (e.getCause() instanceof CoreException) {
+ ErrorDialog
+ .openError(
+ getContainer().getShell(),
+ Messages.WizardNewCompleteOCLFileCreationPage_errorTitle,
+ null, // no special
+ // message
+ ((CoreException) e.getCause())
+ .getStatus());
+ } else {
+ Activator.log(getClass(),
+ "createNewFile()", e.getCause()); //$NON-NLS-1$
+ MessageDialog
+ .openError(
+ getContainer().getShell(),
+ Messages.WizardNewCompleteOCLFileCreationPage_internalErrorTitle,
+ NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_internalErrorTitle,
+ e.getCause().getMessage()));
+ }
+ }
+ });
+ }
+ }
+ };
+ try {
+ getContainer().run(true, true, op);
+ } catch (InterruptedException e) {
+ return null;
+ } catch (InvocationTargetException e) {
+ // Execution Exceptions are handled above but we may still get
+ // unexpected runtime errors.
+ Activator
+ .log(getClass(), "createNewFile()", e.getTargetException()); //$NON-NLS-1$
+ MessageDialog
+ .open(
+ MessageDialog.ERROR,
+ getContainer().getShell(),
+ Messages.WizardNewCompleteOCLFileCreationPage_internalErrorTitle,
+ NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_internalErrorMessage,
+ e.getTargetException().getMessage()), SWT.SHEET);
+
+ return null;
+ }
+
+ return newFile;
+ }
+
+ protected IPath getNewFilePath() {
+ final IPath containerPath = dialog.getGroup().getContainerFullPath();
+ return containerPath.append(dialog.getGroup().getResource());
+ }
+
+ /**
+ * (non-Javadoc) Method declared on IDialogPage.
+ */
+ public void createControl(Composite parent) {
+ dialog = new ExtendedNewCompleteOCLFileDialog(getShell(), null,
+ currentSelection, this);
+
+ Composite topLevel = dialog.createControlArea(parent);
+
+ validatePage();
+ // Show description on opening
+ setErrorMessage(null);
+ setMessage(null);
+ setControl(topLevel);
+ }
+
+ /**
+ * Returns the current full path of the containing resource as entered or
+ * selected by the user, or its anticipated initial value.
+ *
+ * @return the container's full path, anticipated initial value, or
+ * <code>null</code> if no path is known
+ */
+ public IPath getContainerFullPath() {
+ return dialog.getGroup().getContainerFullPath();
+ }
+
+ /**
+ * Returns the current file name as entered by the user, or its anticipated
+ * initial value. <br>
+ * <br>
+ * The current file name will include the file extension if the
+ * preconditions are met.
+ *
+ * @see WizardNewFileCreationPage#setFileExtension(String)
+ *
+ * @return the file name, its anticipated initial value, or
+ * <code>null</code> if no file name is known
+ */
+ public String getFileName() {
+ if (newFile != null) {
+ return dialog.getGroup().getResource();
+ }
+ return null;
+ }
+
+ /**
+ * Returns a stream containing the initial contents to be given to new
+ * complete OCL file resource instances.
+ *
+ * @return initial contents to be given to new complete OCL file resource
+ * instances
+ */
+ public InputStream getInitialContents() {
+ if (newFile != null && dialog != null && dialog.isURIFieldValid()) {
+ return new ByteArrayInputStream(getInitialContentsAsString()
+ .getBytes());
+ }
+ return null;
+ }
+
+ /**
+ * Returns a string containing the initial contents to be given to new
+ * complete OCL file resource instances.
+ *
+ * @return contents to be given to new complete OCL file resource instances
+ */
+ protected String getInitialContentsAsString() {
+ String line = new String("import '"); //$NON-NLS-1$
+ line = line.concat(dialog.getMetamodelNsURI()).concat("'\n"); //$NON-NLS-1$
+
+ String firstPackageName = "undefined_root_package_name"; //$NON-NLS-1$
+
+ if (dialog.getFirstPackage() != null) {
+ firstPackageName = dialog.getFirstPackage().getName();
+ }
+
+ line = line + "\npackage " + firstPackageName + "\n\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ line = line + "\tcontext type\n"; //$NON-NLS-1$
+ line = line + "\tinv InvariantName: true\n\n"; //$NON-NLS-1$
+ line = line + "endpackage\n"; //$NON-NLS-1$
+ return line;
+ }
+
+ /**
+ * The <code>WizardNewFileCreationPage</code> implementation of this
+ * <code>Listener</code> method handles all events and enablements for
+ * controls on this page. Subclasses may extend.
+ */
+ public void handleEvent(Event event) {
+ setPageComplete(validatePage());
+ }
+
+ /**
+ * Returns whether this page's controls currently all contain valid values.
+ *
+ * @return <code>true</code> if all controls are valid, and
+ * <code>false</code> if at least one is invalid
+ */
+ protected boolean validatePage() {
+ boolean valid = true;
+ setMessage(Messages.WizardNewCompleteOCLFileCreationPage_createCompleteOCLFileBasedOnModel);
+ setErrorMessage(null);
+
+ if (!dialog.getGroup().areAllValuesValid()) {
+ // if blank name then fail silently
+ if (dialog.getGroup().getProblemType() == ResourceAndContainerGroup.PROBLEM_RESOURCE_EMPTY
+ || dialog.getGroup().getProblemType() == ResourceAndContainerGroup.PROBLEM_CONTAINER_EMPTY) {
+ setMessage(dialog.getGroup().getProblemMessage());
+ setErrorMessage(null);
+ } else {
+ setErrorMessage(dialog.getGroup().getProblemMessage());
+ }
+ valid = false;
+ }
+
+ String resourceName = dialog.getGroup().getResource();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IStatus result = workspace.validateName(resourceName, IResource.FILE);
+ if (!result.isOK()) {
+ setErrorMessage(result.getMessage());
+ return false;
+ }
+
+ if (dialog.getGroup().getAllowExistingResources()) {
+ String problemMessage = NLS.bind(
+ Messages.WizardNewCompleteOCLFileCreationPage_nameExists,
+ getFileName());
+ IPath resourcePath = getContainerFullPath().append(getFileName());
+ if (workspace.getRoot().getFolder(resourcePath).exists()) {
+ setErrorMessage(problemMessage);
+ valid = false;
+ }
+ if (workspace.getRoot().getFile(resourcePath).exists()) {
+ setMessage(problemMessage, IMessageProvider.WARNING);
+ }
+ }
+
+ if (isFilteredByParent()) {
+ setMessage(
+ Messages.WizardNewCompleteOCLFileCreationPage_resourceWillBeFilteredWarning,
+ IMessageProvider.ERROR);
+ valid = false;
+ }
+ return valid;
+ }
+
+ private boolean isFilteredByParent() {
+ IPath containerPath = dialog.getGroup().getContainerFullPath();
+ if (containerPath == null)
+ return false;
+ String resourceName = dialog.getGroup().getResource();
+ if (resourceName == null)
+ return false;
+ if (resourceName.length() > 0) {
+ IPath newFolderPath = containerPath.append(resourceName);
+ IFile newFileHandle = createFileHandle(newFolderPath);
+ IWorkspace workspace = newFileHandle.getWorkspace();
+ return !workspace.validateFiltered(newFileHandle).isOK();
+ }
+ return false;
+ }
+
+ protected void setDialog(ExtendedNewCompleteOCLFileDialog dialog) {
+ this.dialog = dialog;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(boolean visible) {
+ super.setVisible(visible);
+ if (visible) {
+ dialog.getGroup().setFocus();
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.ocl.common.ui/icons/OCLModelFile.gif b/plugins/org.eclipse.ocl.common.ui/icons/OCLModelFile.gif
new file mode 100644
index 0000000..2945103
--- /dev/null
+++ b/plugins/org.eclipse.ocl.common.ui/icons/OCLModelFile.gif
Binary files differ
diff --git a/plugins/org.eclipse.ocl.common.ui/src/org/eclipse/ocl/common/ui/internal/Activator.java b/plugins/org.eclipse.ocl.common.ui/src/org/eclipse/ocl/common/ui/internal/Activator.java
index a39d490..9aca910 100644
--- a/plugins/org.eclipse.ocl.common.ui/src/org/eclipse/ocl/common/ui/internal/Activator.java
+++ b/plugins/org.eclipse.ocl.common.ui/src/org/eclipse/ocl/common/ui/internal/Activator.java
@@ -7,14 +7,32 @@
*
* Contributors:
* E.D.Willink - initial API and implementation
+ * Obeo - add log and image descriptor facilities
*******************************************************************************/
package org.eclipse.ocl.common.ui.internal;
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.internal.misc.StatusUtil;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-public class Activator implements BundleActivator {
+@SuppressWarnings("restriction")
+public class Activator extends AbstractUIPlugin implements BundleActivator {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.ocl.common.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
private static BundleContext context;
static BundleContext getContext() {
@@ -25,6 +43,7 @@ public class Activator implements BundleActivator {
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
+ @Override
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
}
@@ -33,8 +52,138 @@ public class Activator implements BundleActivator {
* (non-Javadoc)
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
+ @Override
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Return the workspace used by the workbench
+ *
+ * This method is internal to the workbench and must not be called by any
+ * plugins.
+ */
+ public static IWorkspace getPluginWorkspace() {
+ return ResourcesPlugin.getWorkspace();
+ }
+
+ /**
+ * Gets the Id of the Plugin
+ *
+ * @return the Plugin Identifier
+ */
+ private static String getId() {
+ return getDefault().getBundle().getSymbolicName();
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in
+ * relative path
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+ /**
+ * Logs the given message and throwable to the platform log.
+ *
+ * If you have a status object in hand call log(String, IStatus) instead.
+ *
+ * This convenience method is for internal use by the IDE Workbench only and
+ * must not be called outside the IDE Workbench.
+ *
+ * @param message
+ * A high level UI message describing when the problem happened.
+ * @param t
+ * The throwable from where the problem actually occurred.
+ */
+ public static void log(String message, Throwable t) {
+ IStatus status = StatusUtil.newStatus(IStatus.ERROR, message, t);
+ log(message, status);
+ }
+
+ /**
+ * Logs the given throwable to the platform log, indicating the class and
+ * method from where it is being logged (this is not necessarily where it
+ * occurred).
+ *
+ * This convenience method is for internal use by the IDE Workbench only and
+ * must not be called outside the IDE Workbench.
+ *
+ * @param clazz
+ * The calling class.
+ * @param methodName
+ * The calling method name.
+ * @param t
+ * The throwable from where the problem actually occurred.
+ */
+ public static void log(@SuppressWarnings("rawtypes") Class clazz, String methodName, Throwable t) {
+ String msg = MessageFormat.format("Exception in {0}.{1}: {2}", //$NON-NLS-1$
+ new Object[]{clazz.getName(), methodName, t});
+ log(msg, t);
+ }
+
+ /**
+ * Logs the given message and status to the platform log.
+ *
+ * This convenience method is for internal use by the IDE Workbench only and
+ * must not be called outside the IDE Workbench.
+ *
+ * @param message
+ * A high level UI message describing when the problem happened.
+ * May be <code>null</code>.
+ * @param status
+ * The status describing the problem. Must not be null.
+ */
+ public static void log(String message, IStatus status) {
+
+ if (message != null) {
+ getDefault().getLog().log(
+ StatusUtil.newStatus(IStatus.ERROR, message, null));
+ }
+
+ getDefault().getLog().log(status);
+ }
+
+
+ /**
+ * Logs a message with given level into the Eclipse log file
+ *
+ * @param message
+ * the message to log
+ * @param severity
+ * the message priority
+ */
+ public static void log(Exception e) {
+ log(e.getMessage(), IStatus.ERROR, e);
+ }
+
+ /**
+ * Logs a message with given level into the Eclipse log file
+ *
+ * @param message
+ * the message to log
+ * @param severity
+ * the message priority
+ * @param e
+ * exception to log
+ */
+ public static void log(String message, int severity, Exception e) {
+ IStatus status = new Status(severity, getId(), severity, message, e);
+ getDefault().getLog().log(status);
+ }
}
diff --git a/plugins/org.eclipse.ocl.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.ocl.common/META-INF/MANIFEST.MF
index cb83132..3a6d827 100644
--- a/plugins/org.eclipse.ocl.common/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.ocl.common/META-INF/MANIFEST.MF
@@ -17,5 +17,6 @@ Export-Package: org.eclipse.ocl.common,
org.eclipse.ocl.common.internal.preferences,
org.eclipse.ocl.common.preferences
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
- org.eclipse.emf.ecore;bundle-version="[2.7.0,3.0.0)";visibility:=reexport
+ org.eclipse.emf.ecore;bundle-version="[2.7.0,3.0.0)";visibility:=reexport,
+ org.eclipse.jdt.annotation
Bundle-Vendor: %providerName
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/.classpath b/tests/org.eclipse.ocl.examples.ui.tests/.classpath
new file mode 100644
index 0000000..64c5e31
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/.project b/tests/org.eclipse.ocl.examples.ui.tests/.project
new file mode 100644
index 0000000..22e62ce
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ocl.examples.ui.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/.settings/org.eclipse.jdt.core.prefs b/tests/org.eclipse.ocl.examples.ui.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..af0f20f
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.ocl.examples.ui.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..a45f415
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Tests
+Bundle-SymbolicName: org.eclipse.ocl.examples.ui.tests
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Require-Bundle: org.eclipse.ocl.examples.ui;bundle-version="1.1.100",
+ org.eclipse.ui.console;bundle-version="3.5.200",
+ org.junit;bundle-version="4.11.0",
+ org.eclipse.emf.ecore.xmi;bundle-version="2.9.0",
+ org.eclipse.ocl.examples.domain;bundle-version="3.4.0",
+ org.eclipse.core.resources;bundle-version="3.8.100",
+ org.eclipse.core.runtime;bundle-version="3.9.0",
+ org.eclipse.emf.ecore.editor;bundle-version="2.9.0",
+ org.eclipse.ocl.examples.impactanalyzer.testmodel.ngpm;bundle-version="3.1.300"
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/build.properties b/tests/org.eclipse.ocl.examples.ui.tests/build.properties
new file mode 100644
index 0000000..596573f
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
+additional.bundles = org.eclipse.jdt.annotation
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForPerformFinishTest.java b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForPerformFinishTest.java
new file mode 100644
index 0000000..d6af347
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForPerformFinishTest.java
@@ -0,0 +1,54 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.test.ui;
+
+import java.util.Iterator;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ocl.examples.ui.wizards.WizardNewCompleteOCLFileCreationPage;
+
+/**
+ * Wizard creation page to test performFinish of WizardNewCompleteOCLFileCreation
+ *
+ */
+public class WizardCreationPageForPerformFinishTest
+ extends WizardNewCompleteOCLFileCreationPage {
+
+ private IStructuredSelection selection;
+
+ public WizardCreationPageForPerformFinishTest(IStructuredSelection selection) {
+ super(selection); //$NON-NLS-1$
+ this.selection = selection;
+ }
+
+ @Override
+ protected IPath getNewFilePath() {
+ if (selection != null && !selection.toList().isEmpty()) {
+ @SuppressWarnings("rawtypes")
+ Iterator it = selection.iterator();
+ if (it.hasNext()) {
+ Object next = it.next();
+ if ((next instanceof IFile)) {
+ IFile file = (IFile) next;
+ return file.getParent().getFullPath()
+ .append("/NewOCLFile.ocl");
+ }
+ }
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForTest.java b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForTest.java
new file mode 100644
index 0000000..e70c724
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardCreationPageForTest.java
@@ -0,0 +1,37 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.test.ui;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ocl.examples.ui.dialogs.ExtendedNewCompleteOCLFileDialog;
+import org.eclipse.ocl.examples.ui.wizards.WizardNewCompleteOCLFileCreationPage;
+
+/**
+ * Wizard creation page for test
+ *
+ */
+public class WizardCreationPageForTest
+ extends WizardNewCompleteOCLFileCreationPage {
+
+ public WizardCreationPageForTest(IStructuredSelection selection,
+ ExtendedNewCompleteOCLFileDialog dialog) {
+ super(selection); //$NON-NLS-1$
+ setDialog(dialog);
+ }
+
+ public String getInitialContentsAsString() {
+ return super.getInitialContentsAsString();
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardNewCompleteOCLFileCreationForTest.java b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardNewCompleteOCLFileCreationForTest.java
new file mode 100644
index 0000000..2163f36
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/test/ui/WizardNewCompleteOCLFileCreationForTest.java
@@ -0,0 +1,32 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.test.ui;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ocl.examples.ui.wizards.WizardNewCompleteOCLFileCreation;
+import org.eclipse.ui.IWorkbench;
+
+/**
+ * Wizard allowing the user to create a new OCL rule file.
+ */
+public class WizardNewCompleteOCLFileCreationForTest
+ extends WizardNewCompleteOCLFileCreation {
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ super.page = new WizardCreationPageForPerformFinishTest(selection);
+ addPage(page);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/Test.ecore b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/Test.ecore
new file mode 100644
index 0000000..088b638
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/Test.ecore
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
+ name="Test" nsURI="http://eclipse.org/ocl/examples/ui/tests/test"
+ nsPrefix="test"/>
diff --git a/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/WizardNewCompleteOCLCreationPageTest.java b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/WizardNewCompleteOCLCreationPageTest.java
new file mode 100644
index 0000000..7d19ee3
--- /dev/null
+++ b/tests/org.eclipse.ocl.examples.ui.tests/src/org/eclipse/ocl/examples/ui/tests/WizardNewCompleteOCLCreationPageTest.java
@@ -0,0 +1,204 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2013 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Obeo - initial API and implementation
+ *
+ * </copyright>
+ */
+package org.eclipse.ocl.examples.ui.tests;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.ocl.examples.test.ui.WizardCreationPageForTest;
+import org.eclipse.ocl.examples.test.ui.WizardNewCompleteOCLFileCreationForTest;
+import org.eclipse.ocl.examples.ui.dialogs.ExtendedNewCompleteOCLFileDialog;
+import org.eclipse.ocl.examples.ui.messages.Messages;
+import org.eclipse.ocl.examples.ui.wizards.WizardNewCompleteOCLFileCreation;
+import org.eclipse.ocl.examples.ui.wizards.WizardNewCompleteOCLFileCreationPage;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.PlatformUI;
+import org.junit.Test;
+
+/**
+ * Tests that exercise the new complete OCL creation wizard page.
+ */
+public class WizardNewCompleteOCLCreationPageTest
+ extends TestCase {
+
+ private static final String TEST_ECORE_NAME = "Test.ecore";
+
+ private static final String TEST_PROJECT_NAME = "test-project";
+
+ private static final String PAGE_NAME = "page";
+
+ private static final String EXPECTED_NS_URI = "platform:/resource/"
+ + TEST_PROJECT_NAME + "/" + TEST_ECORE_NAME;
+
+ private static final String TEST_ECORE_PATH = "/" + TEST_PROJECT_NAME + "/"
+ + TEST_ECORE_NAME;
+
+ private static final String EXPECTED_PACKAGE_NAME = "Test";
+
+ private WizardNewCompleteOCLFileCreationPage page = null;
+
+ private ExtendedNewCompleteOCLFileDialog dialog = null;
+
+ private IProject project = null;
+
+ private IFile modelFile = null;
+
+ private IStructuredSelection selection = null;
+
+ private WizardNewCompleteOCLFileCreation oclFileCreationWizard = null;
+
+ public WizardNewCompleteOCLCreationPageTest(String name) {
+ super(name);
+ }
+
+ private IWorkbench getWorkbench() {
+ return PlatformUI.getWorkbench();
+ }
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp()
+ throws Exception {
+ super.setUp();
+
+ IEclipsePreferences prefs = InstanceScope.INSTANCE
+ .getNode(ResourcesPlugin.PI_RESOURCES);
+ prefs.putBoolean(ResourcesPlugin.PREF_LIGHTWEIGHT_AUTO_REFRESH, true);
+
+ final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IProjectDescription description = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(TEST_PROJECT_NAME);
+ project = root.getProject(description.getName());
+ if (project.exists()) {
+ project.delete(true, true, new NullProgressMonitor());
+ }
+ project.create(description, new NullProgressMonitor());
+
+ assertTrue(project.exists());
+
+ project.open(new NullProgressMonitor());
+
+ URL url = getClass().getResource(TEST_ECORE_NAME);
+
+ assertNotNull(url);
+ project.getFile(TEST_ECORE_NAME).create(url.openStream(), true,
+ new NullProgressMonitor());
+
+ modelFile = project.getFile(TEST_ECORE_NAME);
+
+ assertTrue(modelFile.exists());
+
+ selection = new StructuredSelection(modelFile);
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown()
+ throws Exception {
+ super.tearDown();
+ if (project.exists()) {
+ project.delete(true, true, new NullProgressMonitor());
+ }
+ }
+
+ @Test
+ public void test_WizardPage() {
+ oclFileCreationWizard = new WizardNewCompleteOCLFileCreation();
+ oclFileCreationWizard.init(getWorkbench(), selection);
+ page = (WizardNewCompleteOCLFileCreationPage) oclFileCreationWizard
+ .getPage(PAGE_NAME);
+
+ assertTrue(PAGE_NAME.equals(page.getName()));
+ assertTrue(Messages.WizardNewCompleteOCLFileCreationPage_completeOCLFile
+ .equals(page.getTitle()));
+ assertTrue(Messages.WizardNewCompleteOCLFileCreationPage_createCompleteOCLFileBasedOnModel
+ .equals(page.getDescription()));
+ assertNull(page.getErrorMessage());
+ }
+
+ @Test
+ public void test_ExtendedDialog() {
+ dialog = new ExtendedNewCompleteOCLFileDialog(null, null, selection,
+ null);
+ dialog.fillContentsFromWorkspacePath(TEST_ECORE_PATH);
+
+ assertTrue(Messages.WizardNewCompleteOCLFileCreationPage_fileExtension
+ .equals(dialog.getNewFileExtension()));
+ assertTrue(Messages.WizardNewCompleteOCLFileCreationPage_oclFileNameLabel
+ .equals(dialog.getNewFileLabel()));
+ assertTrue(Messages.WizardNewCompleteOCLFileCreationPage_fileName
+ .equals(dialog.getNewFileName()));
+ assertTrue(Messages.WizardNewCompleteOCLFileCreationPage_file
+ .equals(dialog.getResourceType()));
+ assertTrue(EXPECTED_NS_URI.equals(dialog.getMetamodelNsURI()));
+ assertTrue(EXPECTED_PACKAGE_NAME.equals(dialog.getFirstPackage()
+ .getName()));
+ assertTrue(TEST_ECORE_PATH.equals(dialog.getURI().toString()));
+ }
+
+ @Test
+ public void test_WizardPage_CreatedFileContent() {
+ dialog = new ExtendedNewCompleteOCLFileDialog(null, null, selection,
+ null);
+ dialog.fillContentsFromWorkspacePath(TEST_ECORE_PATH);
+
+ WizardCreationPageForTest oclFileCreationWizardPage = new WizardCreationPageForTest(
+ selection, dialog);
+
+ assertTrue(oclFileCreationWizardPage.getInitialContentsAsString()
+ .equals(getExpectedContents()));
+ }
+
+ @Test
+ public void test_WizardPage_FileCreation() {
+ IWorkbenchWizard wizard = new WizardNewCompleteOCLFileCreationForTest();
+ wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(
+ modelFile));
+
+ WizardDialog dialog = new WizardDialog(new Shell(), wizard);
+ dialog.open();
+
+ wizard.performFinish();
+
+ assertTrue(project.getFile("NewOCLFile.ocl").exists());
+ }
+
+ public String getExpectedContents() {
+ String line = new String("import '"); //$NON-NLS-1$
+ line = line.concat(dialog.getMetamodelNsURI()).concat("'\n"); //$NON-NLS-1$
+ String firstPackageName = dialog.getFirstPackage().getName(); //$NON-NLS-1$
+ line = line + "\npackage " + firstPackageName + "\n\n"; //$NON-NLS-1$ //$NON-NLS-2$
+ line = line + "\tcontext type\n"; //$NON-NLS-1$
+ line = line + "\tinv InvariantName: true\n\n"; //$NON-NLS-1$
+ line = line + "endpackage\n"; //$NON-NLS-1$
+ return line;
+ }
+}