Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.papyrus.wizards/src')
-rw-r--r--core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/Activator.java62
-rw-r--r--core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/CreateModelWizard.java169
-rw-r--r--core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/InitDiagramAction.java95
-rw-r--r--core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/NewModelFilePage.java91
-rw-r--r--core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectDiagramKindPage.java203
-rw-r--r--core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectRootElementPage.java178
6 files changed, 798 insertions, 0 deletions
diff --git a/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/Activator.java b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/Activator.java
new file mode 100644
index 00000000000..65fe3a4afb4
--- /dev/null
+++ b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/Activator.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Obeo.
+ * 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
+ *******************************************************************************/
+package org.eclipse.papyrus.wizards;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.wizards";
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/CreateModelWizard.java b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/CreateModelWizard.java
new file mode 100644
index 00000000000..c881f5b8ee9
--- /dev/null
+++ b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/CreateModelWizard.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Obeo.
+ * 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
+ *******************************************************************************/
+package org.eclipse.papyrus.wizards;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.papyrus.core.IPapyrusUIConstants;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.core.utils.DiResourceSet;
+import org.eclipse.papyrus.core.utils.PapyrusTrace;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Create new model file and initialize a selected diagram. This wizard create several files : *.di2 : the DI file to store Di diagrams and references all external diagrams like GMF diagrams.
+ * *.notation : the file to store pure GMF diagrams *.uml : the standard UML file to store UML semantics elements. (Model, Package, Class,...)
+ *
+ * Those files can be used with the PapyrusEditor (see plugin.xml).
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class CreateModelWizard extends Wizard implements INewWizard {
+
+ /** ID of this wizard */
+ public static final String WIZARD_ID = IPapyrusUIConstants.WIZARD_ID + ".createmodel";
+
+ /** New model file page for the file */
+ private NewModelFilePage newModelFilePage;
+
+ /** Select kinf of new diagram the wizard must create */
+ private SelectDiagramKindPage selectDiagramKindPage;
+
+ /** Select the root element containing the new diagram */
+ private SelectRootElementPage selectRootElementPage;
+
+ /** Current workbench */
+ private IWorkbench workbench;
+
+ /**
+ * The URI of the selected domain model. Do not create a new uml model, but use the selected
+ */
+ private URI domainModelURI;
+
+ /**
+ * ResourceSet used to link all Resource (Model and DI)
+ */
+ DiResourceSet diResourceSet;
+
+ public CreateModelWizard() {
+ }
+
+ public CreateModelWizard(URI domainModelURI) {
+ super();
+ this.domainModelURI = domainModelURI;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addPages() {
+ addPage(newModelFilePage);
+ addPage(selectDiagramKindPage);
+ if (domainModelURI != null) {
+ addPage(selectRootElementPage);
+ }
+ }
+
+ /**
+ * Initializes this creation wizard using the passed workbench and object selection.
+ * <p>
+ * This method is called after the no argument constructor and before other methods are called.
+ * </p>
+ *
+ * @param workbench
+ * the current workbench
+ * @param selection
+ * the current object selection
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.workbench = workbench;
+ this.diResourceSet = new DiResourceSet(/* (AdapterFactory) null */);
+ // set the di file name with the selected domain model
+ if (selection != null && !selection.isEmpty()) {
+ if (selection.getFirstElement() instanceof IFile) {
+ IFile file = (IFile) selection.getFirstElement();
+ String extension = file.getFileExtension();
+ if ("uml".equals(extension)) {
+ this.domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
+
+ this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new Papyrus model from an existing semantic model", selection, true);
+ String diModelFileName = (file.getLocation().removeFileExtension().lastSegment());
+ diModelFileName += "." + IPapyrusUIConstants.MODEL_EXTENSION;
+ this.newModelFilePage.setFileName(diModelFileName);
+
+ diResourceSet.loadUMLResource(domainModelURI);
+ Resource resource = diResourceSet.getUMLModelResource();
+ EObject diagramRoot = resource.getContents().get(0);
+ this.selectRootElementPage = new SelectRootElementPage("Select the root element", diagramRoot);
+ }
+ }
+ }
+ if (domainModelURI == null) {
+ this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new empty Papyrus model", selection, false);
+ }
+ selectDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram", newModelFilePage);
+ }
+
+ /**
+ * This method will be invoked, when the "Finish" button is pressed.
+ *
+ * @return <code>true</code> if everything runs without problems, <code>false</code> if an exception must be caught.
+ *
+ */
+ @Override
+ public boolean performFinish() {
+ // create a new file, result != null if successful
+ IFile newFile = newModelFilePage.createNewFile();
+ NewModelFilePage.fileCount++;
+
+ // open newly created file in the editor
+ IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
+ if ((newFile != null) && (page != null)) {
+ // Create needed object
+ diResourceSet.transactionalCreateModelResources(newFile);
+
+ String diagramName = selectDiagramKindPage.getDiagramName();
+ ICreationCommand creationCommand = selectDiagramKindPage.getCreationCommand();
+
+ if (domainModelURI != null) {
+ creationCommand.createDiagram(diResourceSet, selectRootElementPage.getModelElement(), diagramName);
+ } else {
+ creationCommand.createDiagram(diResourceSet, null, diagramName);
+ }
+ try {
+ diResourceSet.saveResources();
+ } catch (IOException e) {
+ PapyrusTrace.log(e);
+ return false;
+ }
+
+ try {
+ IDE.openEditor(page, newFile, true);
+ } catch (PartInitException e) {
+ PapyrusTrace.log(e);
+ return false;
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/InitDiagramAction.java b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/InitDiagramAction.java
new file mode 100644
index 00000000000..125cf9a3e50
--- /dev/null
+++ b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/InitDiagramAction.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Obeo.
+ * 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
+ *******************************************************************************/
+package org.eclipse.papyrus.wizards;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * This action initialize the "CreateModelWizard" with the selected domain file,
+ * and launch the wizard to create Diagram Interchange resources required by
+ * Papyrus editor.
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class InitDiagramAction implements IObjectActionDelegate {
+
+ /**
+ * The active part
+ */
+ private IWorkbenchPart targetPart;
+
+ /**
+ * The current selection;
+ */
+ IStructuredSelection selection;
+
+ /**
+ * The URI of the selected domain file.
+ */
+ private URI domainModelURI;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ this.targetPart = targetPart;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.domainModelURI = null;
+ this.selection = null;
+ action.setEnabled(false);
+ if ((selection instanceof IStructuredSelection) && !selection.isEmpty()) {
+ IFile file = (IFile) ((IStructuredSelection) selection)
+ .getFirstElement();
+ this.domainModelURI = URI.createPlatformResourceURI(file
+ .getFullPath().toString(), true);
+ this.selection = (StructuredSelection) selection;
+ action.setEnabled(true);
+ }
+ }
+
+ /**
+ * @return the current Shell to display dialog
+ */
+ private Shell getShell() {
+ return targetPart.getSite().getShell();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void run(IAction action) {
+ if (domainModelURI != null) {
+ CreateModelWizard wizard = new CreateModelWizard(domainModelURI);
+ wizard.init(targetPart.getSite().getWorkbenchWindow()
+ .getWorkbench(), selection);
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ dialog.create();
+ dialog.getShell().setSize(
+ Math.max(500, dialog.getShell().getSize().x), 500);
+ dialog.open();
+ }
+ }
+
+}
diff --git a/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/NewModelFilePage.java b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/NewModelFilePage.java
new file mode 100644
index 00000000000..d58e37c9a54
--- /dev/null
+++ b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/NewModelFilePage.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Obeo.
+ * 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
+ *******************************************************************************/
+package org.eclipse.papyrus.wizards;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.core.IPapyrusUIConstants;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+import org.eclipse.uml2.uml.resource.UMLResource;
+
+/**
+ * This WizardPage can create an empty .uml2 file for the PapyrusEditor.
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class NewModelFilePage extends WizardNewFileCreationPage {
+
+ /** index for several file creation */
+ protected static int fileCount = 1;
+
+ protected boolean createFromSemanticModel;
+
+ /**
+ * Create a new wizard page instance.
+ *
+ * @param workbench
+ * the current workbench
+ * @param selection
+ * the current object selection
+ * @see PapyrusCreationWizard#init(IWorkbench, IStructuredSelection)
+ */
+ public NewModelFilePage(String title, String description, IStructuredSelection selection, boolean createFromSemanticModel) {
+ super(title, selection);
+ setTitle(title);
+ setDescription(description);
+ this.createFromSemanticModel = createFromSemanticModel;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ if (getFileName() == null || getFileName().length() == 0) {
+ setFileName("umlModel" + fileCount + "." + IPapyrusUIConstants.MODEL_EXTENSION);
+ }
+ setPageComplete(validatePage());
+ }
+
+ /**
+ * Tests if the file name entered in this page is valid.
+ *
+ * @return <code>true</code> if the file name is valid
+ */
+ private boolean validateFilename() {
+ if ((getFileName() != null) && getFileName().endsWith("." + IPapyrusUIConstants.MODEL_EXTENSION)) {
+ // check if a semantic model already exist
+ IPath semanticModelPath = Platform.getLocation().append(getContainerFullPath()).append(getFileName()).removeFileExtension().addFileExtension(UMLResource.FILE_EXTENSION);
+ if (!createFromSemanticModel && semanticModelPath.toFile().exists()) {
+ setErrorMessage("'" + semanticModelPath.lastSegment() + "' already exist. " + "Select this and restart this wizard to create a new '" + IPapyrusUIConstants.MODEL_EXTENSION
+ + "' model " + "from an existing semantic model!");
+ } else {
+ return true;
+ }
+ } else {
+ setErrorMessage("The 'file' name must end with the extension ." + IPapyrusUIConstants.MODEL_EXTENSION);
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean validatePage() {
+ return super.validatePage() && validateFilename();
+ }
+
+}
diff --git a/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectDiagramKindPage.java b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectDiagramKindPage.java
new file mode 100644
index 00000000000..cbdfe3328f0
--- /dev/null
+++ b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectDiagramKindPage.java
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Obeo.
+ * 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
+ *******************************************************************************/
+package org.eclipse.papyrus.wizards;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.papyrus.core.extension.NotFoundException;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
+import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommand;
+import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
+import org.eclipse.papyrus.core.utils.PapyrusTrace;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * This WizardPage to select the kind of Papyrus Diagram.
+ * List all kind of diagrams registered with creationCommand attribute in PapyrusDiagram Eclipse extension.
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class SelectDiagramKindPage extends WizardPage {
+
+ private final static String DIAGRAM_KIND_ID="diagramKindId";
+
+ /**
+ * The previous page containing the model fileName
+ */
+ NewModelFilePage modelFilePage;
+
+ /**
+ * The creation command registry
+ */
+ ICreationCommandRegistry creationCommandRegistry;
+
+ /**
+ * The selected creation command
+ */
+ private ICreationCommand creationCommand;
+
+ /**
+ * The diagram name text field
+ */
+ private Text nameText;
+
+ /**
+ * @return the new diagram name
+ */
+ protected String getDiagramName(){
+ return nameText.getText();
+ }
+
+ /**
+ * @return the creation command
+ */
+ protected ICreationCommand getCreationCommand() {
+ return creationCommand;
+ }
+
+ /**
+ * The list containing all registered diagram kind
+ */
+ private CCombo diagramList = null;
+
+ protected SelectDiagramKindPage(String pageName, NewModelFilePage modelFilePage) {
+ super(pageName);
+ setTitle("Select a new Diagram");
+ setDescription("Select a new Diagram");
+ this.modelFilePage=modelFilePage;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createControl(Composite parent) {
+ Composite root = new Composite(parent, SWT.NONE);
+ GridLayout gridLayout = new GridLayout();
+ root.setLayout(gridLayout);
+ Group composite = new Group(root, 0);
+ composite.setText("Initialization information");
+
+ composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ gridLayout = new GridLayout(2, false);
+ gridLayout.marginWidth = 10;
+ composite.setLayout(gridLayout);
+ createDialogArea(composite);
+
+ setControl(root);
+ }
+
+ private void createDialogArea(Composite composite) {
+ createDiagramKindForm(composite);
+ createNameForm(composite);
+ }
+
+ private void createDiagramKindForm(Composite composite) {
+ //create label
+ Label label = new Label(composite, SWT.TRAIL);
+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+ label.setLayoutData(data);
+ label.setText("Select diagram kind:");
+
+ //create list of diagrams kind
+ diagramList = new CCombo(composite, SWT.BORDER);
+ data = new GridData(SWT.FILL, SWT.FILL, true, false);
+ diagramList.setLayoutData(data);
+ fillList(diagramList);
+ diagramList.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {}
+
+ public void widgetSelected(SelectionEvent e) {
+ handleListSelected();
+ }
+ });
+ }
+
+ private void createNameForm(Composite composite){
+ Label label = new Label(composite, SWT.TRAIL);
+ GridData data = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
+ label.setLayoutData(data);
+ label.setText("Diagram Name:");
+
+ nameText = new Text(composite, SWT.BORDER);
+ data = new GridData(GridData.FILL_HORIZONTAL);
+ nameText.setLayoutData(data);
+ nameText.setText("NewDiagram");
+ nameText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+ dialogChanged();
+ }
+
+ /**
+ * Validate the changes on the page.
+ */
+ private void dialogChanged() {
+ if ((nameText.getText() == null) || nameText.getText().length()==0) {
+ updateStatus("The diagram name must entered");
+ return;
+ }
+ updateStatus(null);
+ }
+
+ private void fillList(CCombo list) {
+ for(CreationCommandDescriptor desc:getCreationCommandRegistry().getCommandDescriptors()){
+ list.add(desc.getLabel());
+ list.setData(DIAGRAM_KIND_ID+list.getItemCount(), desc.getCommandId() );
+ }
+ if (diagramList.getItemCount() > 0) {
+ diagramList.select(0);
+ handleListSelected();
+ }
+ }
+
+ private void handleListSelected() {
+ int i = diagramList.getSelectionIndex();
+ String diagramKindId = (String)diagramList.getData(DIAGRAM_KIND_ID+(i+1));
+ try {
+ this.creationCommand = getCreationCommandRegistry().getCommand(diagramKindId);
+ } catch (NotFoundException e) {
+ PapyrusTrace.log(e);
+ }
+ }
+
+ private ICreationCommandRegistry getCreationCommandRegistry(){
+ if(creationCommandRegistry==null){
+ this.creationCommandRegistry = new CreationCommandRegistry(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
+ }
+ return creationCommandRegistry;
+ }
+
+ /**
+ * Update page status.
+ *
+ * @param message
+ * is the error message.
+ */
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+
+}
diff --git a/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectRootElementPage.java b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectRootElementPage.java
new file mode 100644
index 00000000000..c3d22072b6a
--- /dev/null
+++ b/core/org.eclipse.papyrus.wizards/src/org/eclipse/papyrus/wizards/SelectRootElementPage.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Obeo.
+ * 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
+ *******************************************************************************/
+package org.eclipse.papyrus.wizards;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
+import org.eclipse.emf.ecore.util.FeatureMap;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.IWrapperItemProvider;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+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.wizard.WizardPage;
+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.Label;
+
+/**
+ * Wizard page that allows to select element from model.
+ *
+ * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
+ */
+public class SelectRootElementPage extends WizardPage {
+
+ /**
+ * The selected model element
+ */
+ protected EObject selectedModelElement;
+
+ /**
+ * TreeViewer use to display the content of the domain model
+ */
+ private TreeViewer modelViewer;
+
+ /**
+ * Constructor
+ *
+ * @param pageName
+ * the page name
+ * @param diagramRoot
+ * the root model element use to initialize the TreeViewer
+ */
+ protected SelectRootElementPage(String pageName, EObject diagramRoot) {
+ super(pageName);
+ setTitle(pageName);
+ setDescription(pageName);
+ this.setModelElement(diagramRoot);
+ }
+
+ /**
+ * @return the selected model element
+ */
+ public EObject getModelElement() {
+ return selectedModelElement;
+ }
+
+ /**
+ * Set the selected model element
+ *
+ * @param modelElement
+ */
+ public void setModelElement(EObject modelElement) {
+ selectedModelElement = modelElement;
+ if (modelViewer != null) {
+ if (selectedModelElement != null) {
+ modelViewer.setInput(selectedModelElement.eResource());
+ modelViewer.setSelection(new StructuredSelection(
+ selectedModelElement));
+ } else {
+ modelViewer.setInput(null);
+ }
+ setPageComplete(validatePage());
+ }
+ }
+
+ public void createControl(Composite parent) {
+ initializeDialogUnits(parent);
+
+ Composite plate = new Composite(parent, SWT.NONE);
+ plate.setLayoutData(new GridData(GridData.FILL_BOTH));
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = 0;
+ plate.setLayout(layout);
+ setControl(plate);
+
+ Label label = new Label(plate, SWT.NONE);
+ //label.setText("Select the root model element");
+ label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+
+ modelViewer = new TreeViewer(plate, SWT.SINGLE | SWT.H_SCROLL
+ | SWT.V_SCROLL | SWT.BORDER);
+
+ GridData layoutData = new GridData(GridData.FILL_BOTH);
+ layoutData.heightHint = 300;
+ layoutData.widthHint = 300;
+ modelViewer.getTree().setLayoutData(layoutData);
+ AdapterFactory adapterFactory = createAdapterFactory();
+ modelViewer.setContentProvider(new AdapterFactoryContentProvider(
+ adapterFactory));
+ modelViewer.setLabelProvider(new AdapterFactoryLabelProvider(
+ adapterFactory));
+ if (selectedModelElement != null) {
+ modelViewer.setInput(selectedModelElement.eResource());
+ modelViewer.setSelection(new StructuredSelection(
+ selectedModelElement));
+ }
+
+ modelViewer
+ .addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ updateSelection((IStructuredSelection) event
+ .getSelection());
+ }
+ });
+
+ setPageComplete(validatePage());
+ }
+
+ protected void updateSelection(IStructuredSelection selection) {
+ selectedModelElement = null;
+ if (selection.size() == 1) {
+ Object selectedElement = selection.getFirstElement();
+ if (selectedElement instanceof IWrapperItemProvider) {
+ selectedElement = ((IWrapperItemProvider) selectedElement)
+ .getValue();
+ }
+ if (selectedElement instanceof FeatureMap.Entry) {
+ selectedElement = ((FeatureMap.Entry) selectedElement)
+ .getValue();
+ }
+ if (selectedElement instanceof EObject) {
+ selectedModelElement = (EObject) selectedElement;
+ }
+ }
+ setPageComplete(validatePage());
+ }
+
+ protected boolean validatePage() {
+ if (selectedModelElement == null) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ protected ComposedAdapterFactory createAdapterFactory() {
+ List<AdapterFactory> factories = new ArrayList<AdapterFactory>();
+ fillItemProviderFactories(factories);
+ return new ComposedAdapterFactory(factories);
+ }
+
+ protected void fillItemProviderFactories(List<AdapterFactory> factories) {
+ // custom icons for model elements
+ factories.add(new ComposedAdapterFactory(
+ ComposedAdapterFactory.Descriptor.Registry.INSTANCE));
+ factories.add(new EcoreItemProviderAdapterFactory());
+ factories.add(new ReflectiveItemProviderAdapterFactory());
+ }
+}

Back to the top