Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui')
-rwxr-xr-xplugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java65
-rwxr-xr-xplugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java64
-rwxr-xr-xplugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/Messages.java49
-rwxr-xr-xplugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/messages.properties21
-rwxr-xr-xplugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java243
-rwxr-xr-xplugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java478
6 files changed, 920 insertions, 0 deletions
diff --git a/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java
new file mode 100755
index 00000000..4a90d3e1
--- /dev/null
+++ b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/Activator.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2017 CEA LIST.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.cdo.uml.diagram.internal.ui;
+
+import org.eclipse.papyrus.infra.core.log.LogHelper;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.cdo.uml.diagram.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /** Logging helper */
+ public static LogHelper log = new LogHelper();
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ super();
+ }
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+
+ // register the log helper
+ log.setPlugin(plugin);
+
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ log = null;
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java
new file mode 100755
index 00000000..9d7a3454
--- /dev/null
+++ b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/handlers/NewModelHandler.java
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 CEA LIST.
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.uml.diagram.internal.ui.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.emf.cdo.CDOObject;
+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.net4j.util.ui.UIUtil;
+import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
+import org.eclipse.papyrus.uml.diagram.wizards.wizards.InitModelWizard;
+import org.eclipse.ui.ISources;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * This is the NewModelHandler type. Enjoy.
+ */
+public class NewModelHandler extends AbstractHandler {
+
+ public NewModelHandler() {
+ super();
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ setEnabled(event.getApplicationContext());
+
+ if (isEnabled()) {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ if (selection instanceof IStructuredSelection) {
+ InitModelWizard wizard = new InitModelWizard();
+
+ wizard.init(HandlerUtil.getActiveWorkbenchWindow(event).getWorkbench(), (IStructuredSelection) selection);
+
+ WizardDialog dlg = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
+ dlg.open();
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ Object variable = HandlerUtil.getVariable(evaluationContext, ISources.ACTIVE_CURRENT_SELECTION_NAME);
+ ISelection selection = variable instanceof ISelection ? (ISelection) variable : StructuredSelection.EMPTY;
+ CDOObject cdoObject = CDOUtils.adapt(UIUtil.getElement(selection), CDOObject.class);
+
+ setBaseEnabled((cdoObject == null) || !CDOUtils.isReadOnly(cdoObject));
+ }
+}
diff --git a/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/Messages.java b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/Messages.java
new file mode 100755
index 00000000..d64c7bd2
--- /dev/null
+++ b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/Messages.java
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ * Eike Stepper (CEA) - bug 466520
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.uml.diagram.internal.ui.l10n;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * This is the Messages type. Enjoy.
+ */
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.cdo.uml.diagram.internal.ui.l10n.messages"; //$NON-NLS-1$
+
+ public static String NewModelPage_0;
+
+ public static String NewModelPage_1;
+
+ public static String NewModelPage_16;
+
+ public static String NewModelPage_17;
+
+ public static String NewModelPage_18;
+
+ public static String NewModelPage_19;
+
+ public static String NewModelPage_20;
+
+ public static String NewModelPage_2;
+
+ public static String NewModelPage_3;
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/messages.properties b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/messages.properties
new file mode 100755
index 00000000..66b16c2c
--- /dev/null
+++ b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/l10n/messages.properties
@@ -0,0 +1,21 @@
+#############################################################################
+# Copyright (c) 2013, 2017 CEA LIST 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:
+# CEA LIST - Initial API and implementation
+# Eike Stepper (CEA) - bug 466520
+#############################################################################
+NewModelPage_0=New {0} Model
+NewModelPage_1=Create a new {0} model
+NewModelPage_16=The checkout "{0}" does not exist.
+NewModelPage_17=The new model resource name is required.
+NewModelPage_18=The resource "{0}" already exists.
+NewModelPage_19=The specified folder does not exist and will be created.
+NewModelPage_20=The specified folder cannot be created.
+NewModelPage_2=Enter or select the parent folder:
+NewModelPage_3=Resource name:
diff --git a/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java
new file mode 100755
index 00000000..1c984ac1
--- /dev/null
+++ b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/CDONewModelStorageProvider.java
@@ -0,0 +1,243 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 429242
+ * Eike Stepper (CEA) - bug 466520
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.uml.diagram.internal.ui.wizards;
+
+import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.adapt;
+import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.getSelectedResourceURI;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
+import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.cdo.internal.core.CDOUtils;
+import org.eclipse.papyrus.cdo.internal.ui.editors.PapyrusCDOEditorInput;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectArchitectureContextPage;
+import org.eclipse.papyrus.uml.diagram.wizards.providers.AbstractNewModelStorageProvider;
+import org.eclipse.papyrus.uml.diagram.wizards.wizards.CreateModelWizard;
+import org.eclipse.papyrus.uml.diagram.wizards.wizards.InitModelWizard;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IEditorInput;
+
+import com.google.common.eventbus.EventBus;
+
+/**
+ * This is the CDONewModelStorageProvider type. Enjoy.
+ */
+public class CDONewModelStorageProvider extends AbstractNewModelStorageProvider {
+
+ private final EventBus bus = new EventBus("NewCDOModelWizard"); //$NON-NLS-1$
+
+ private CreateModelWizard wizard;
+
+ private SelectArchitectureContextPage newDiagramCategoryPage;
+
+ private NewModelPage newModelPage;
+
+ public CDONewModelStorageProvider() {
+ super();
+ }
+
+ @Override
+ public boolean canHandle(IStructuredSelection initialSelection) {
+ for (Object next : initialSelection.toList()) {
+ if (CDOUtils.isCDOObject(adapt(next, EObject.class))) {
+ return true;
+ }
+
+ if (adapt(next, CDOCheckout.class) != null) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void init(CreateModelWizard wizard, IStructuredSelection selection) {
+ super.init(wizard, selection);
+
+ this.wizard = wizard;
+ newModelPage = createNewModelPage(selection);
+ createSelectProviderPart();
+
+ CDOCheckout checkout = getRepository(selection);
+ if (checkout != null) {
+ bus.post(checkout);
+ }
+ newDiagramCategoryPage = createNewArchitectureContextPage(selection);
+ }
+
+ /**
+ * Gets the contextual repository, if any, from a selection.
+ *
+ * @param selection
+ * a selection
+ *
+ * @return the repository that is or contains the {@code selection}
+ */
+ static CDOCheckout getRepository(IStructuredSelection selection) {
+ CDOCheckout result = null;
+
+ if (!selection.isEmpty()) {
+ result = adapt(selection.getFirstElement(), CDOCheckout.class);
+ if (result == null) {
+ CDOResourceNode node = adapt(selection.getFirstElement(), CDOResourceNode.class);
+ if (node == null) {
+ EObject object = adapt(selection.getFirstElement(), EObject.class);
+ if (object != null) {
+ CDOObject cdo = CDOUtils.getCDOObject(object);
+ if (cdo != null) {
+ node = cdo.cdoResource();
+ }
+ }
+ }
+
+ if (node != null) {
+ result = CDOExplorerUtil.getCheckout(node.getURI());
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public List<? extends IWizardPage> createPages() {
+ if (newModelPage == null && newDiagramCategoryPage == null) {
+ return Collections.emptyList();
+ }
+
+ return Arrays.asList(newDiagramCategoryPage, newModelPage);
+ }
+
+ @Override
+ public SelectArchitectureContextPage getArchitectureContextPage() {
+ return newDiagramCategoryPage;
+ }
+
+
+ /**
+ * Creates the new model page, if required.
+ *
+ * @param selection
+ * the selection
+ *
+ * @return the new model page, or {@code null} if none
+ */
+ protected NewModelPage createNewModelPage(IStructuredSelection selection) {
+ if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard()) {
+
+ return null;
+ }
+
+ if (isCreateFromExistingDomainModel()) {
+ URI uri = getSelectedResourceURI(selection);
+ if (uri != null) {
+ uri = uri.trimFileExtension().appendFileExtension(wizard.getDiagramFileExtension(null));
+ return new NewDiagramForExistingModelPage(selection, wizard.getModelKindName(), bus, uri.lastSegment());
+ }
+ }
+
+ return new NewModelPage(selection, bus, wizard.getModelKindName());
+ }
+
+ protected boolean isCreateFromExistingDomainModel() {
+ return wizard.isInitModelWizard() && ((InitModelWizard) wizard).isCreateFromExistingDomainModel();
+ }
+
+ @Override
+ public URI createNewModelURI(String categoryId) {
+ return newModelPage.createNewModelResourceURI();
+ }
+
+ @Override
+ public IEditorInput createEditorInput(URI uri) {
+ return new PapyrusCDOEditorInput(uri, uri.trimFileExtension().lastSegment());
+ }
+
+ private SelectArchitectureContextPage createNewArchitectureContextPage(IStructuredSelection selection) {
+ if (wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard() || !wizard.isPapyrusRootWizard()) {
+ return null;
+ }
+
+ return new SelectArchitectureContextPage();
+ }
+
+
+ //
+ // Nested types
+ //
+
+ /**
+ * This is the NewDiagramForExistingModelPage type. Enjoy.
+ */
+ protected static class NewDiagramForExistingModelPage extends NewModelPage {
+
+ /** The my diagram resource name. */
+ private final String myDiagramResourceName;
+
+ /**
+ * Instantiates a new new diagram for existing model page.
+ *
+ * @param selection
+ * the selection
+ * @param modelKindName
+ * the user-presentable (translatable) name of the kind of
+ * model to create
+ * @param bus
+ * an event bus for posting events
+ * @param defaultResourceName
+ * the default resource name
+ */
+ public NewDiagramForExistingModelPage(IStructuredSelection selection, String modelKindName, EventBus bus, String defaultResourceName) {
+
+ super(selection, bus, modelKindName);
+
+ myDiagramResourceName = defaultResourceName;
+ setTitle(org.eclipse.papyrus.uml.diagram.wizards.messages.Messages.InitModelWizard_init_papyrus_model);
+ setDescription(org.eclipse.papyrus.uml.diagram.wizards.messages.Messages.InitModelWizard_init_papyrus_model_desc);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+
+ setNewResourceName(myDiagramResourceName);
+ }
+
+ @Override
+ protected void validatePage() {
+ super.validatePage();
+
+ if (getMessageType() < ERROR) {
+ if (!myDiagramResourceName.equals(getNewResourceName())) {
+ setMessage(NLS.bind(org.eclipse.papyrus.uml.diagram.wizards.messages.Messages.InitModelWizard_diagram_name_is_different_from_domain_model, myDiagramResourceName), ERROR);
+ setPageComplete(false);
+ }
+ }
+ };
+
+ }
+}
diff --git a/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java
new file mode 100755
index 00000000..6b73d88b
--- /dev/null
+++ b/plugins/cdo/bundles/org.eclipse.papyrus.cdo.uml.diagram.ui/src/org/eclipse/papyrus/cdo/uml/diagram/internal/ui/wizards/NewModelPage.java
@@ -0,0 +1,478 @@
+/*****************************************************************************
+ * Copyright (c) 2013, 2017 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ * Eike Stepper (CEA) - bug 466520
+ *****************************************************************************/
+package org.eclipse.papyrus.cdo.uml.diagram.internal.ui.wizards;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.cdo.CDOElement;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
+import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
+import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
+import org.eclipse.emf.cdo.explorer.ui.checkouts.CDOCheckoutContentProvider;
+import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.emf.common.util.ECollections;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.jface.layout.GridDataFactory;
+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.osgi.util.NLS;
+import org.eclipse.papyrus.cdo.uml.diagram.internal.ui.l10n.Messages;
+import org.eclipse.papyrus.uml.diagram.wizards.Activator;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import com.google.common.base.Strings;
+import com.google.common.eventbus.EventBus;
+
+/**
+ * This is the NewModelPage type. Enjoy.
+ */
+public class NewModelPage extends WizardPage {
+
+ public static final String PAGE_ID = "NewCDOModel"; //$NON-NLS-1$
+
+ private String resourceType = "model";
+
+ private Text folderText;
+
+ private TreeViewer folderViewer;
+
+ private Text nameText;
+
+ private boolean synchronizingFolderSelection;
+
+ private Object selectedElement;
+
+ private boolean selectedElementRevealed;
+
+ private URI newModelResourceURI;
+
+ public NewModelPage(IStructuredSelection selection, EventBus bus, String modelKindName) {
+ super(PAGE_ID);
+
+ setTitle(NLS.bind(Messages.NewModelPage_0, modelKindName));
+ setDescription(NLS.bind(Messages.NewModelPage_1, modelKindName));
+ setSelection(selection);
+
+ bus.register(this);
+ }
+
+ @Override
+ public void createControl(Composite parentControl) {
+ Composite container = new Composite(parentControl, SWT.NONE);
+ GridDataFactory.fillDefaults().grab(true, true).applyTo(container);
+ container.setLayout(new GridLayout(2, false));
+
+ Label label = new Label(container, SWT.NONE);
+ label.setText(Messages.NewModelPage_2);
+ GridDataFactory.swtDefaults().span(2, 1).applyTo(label);
+
+ folderText = new Text(container, SWT.BORDER);
+ GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(folderText);
+ updateFolderText();
+
+ folderViewer = CDOCheckoutContentProvider.createTreeViewer(container);
+ folderViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
+ folderViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (selectedElementRevealed) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ setSelection(selection);
+ }
+
+ validatePage();
+ }
+ });
+
+ new Label(container, SWT.NONE).setText(Messages.NewModelPage_3);
+
+ nameText = new Text(container, SWT.BORDER);
+ GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText);
+ nameText.setText(getUniqueName("di")); //$NON-NLS-1$
+
+ setControl(container);
+
+ folderText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ // TODO: set parent then revealParent()
+ validatePage();
+ }
+ });
+
+ folderViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ setSelection(selection);
+ updateFolderText();
+ validatePage();
+ }
+ });
+
+ nameText.addModifyListener(new ModifyListener() {
+
+ @Override
+ public void modifyText(ModifyEvent e) {
+ validatePage();
+ }
+ });
+
+ parentControl.getShell().getDisplay().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ revealSelectedElement();
+ validatePage();
+ }
+ });
+ }
+
+ public String getNewResourceName() {
+ return (nameText == null) ? null : nameText.getText().trim();
+ }
+
+ public URI createNewModelResourceURI() {
+ return newModelResourceURI;
+ }
+
+ public URI createSelectedElementURI() {
+ if (selectedElement instanceof CDOCheckout) {
+ CDOCheckout checkout = (CDOCheckout) selectedElement;
+ return checkout.getURI();
+ }
+
+ if (selectedElement instanceof CDOResourceNode) {
+ CDOResourceNode resourceNode = (CDOResourceNode) selectedElement;
+ return resourceNode.getURI();
+ }
+
+ return null;
+ }
+
+ /**
+ * Diagram extension changed.
+ *
+ * @param newExtension
+ * the new extension
+ * @return result of validation of the new extension
+ */
+ public IStatus diagramExtensionChanged(String newExtension) {
+ String currentExtension = getExtension();
+ if (!newExtension.equals(currentExtension)) {
+
+ String oldFileName = getNewResourceName();
+ String base = oldFileName;
+ if (currentExtension != null) {
+ // take one off for the '.'
+ base = base.substring(0, base.length() - currentExtension.length() - 1);
+ }
+ String newFileName = getUniqueName(newExtension);
+
+ setNewResourceName(newFileName);
+
+ String message1 = org.eclipse.papyrus.uml.diagram.wizards.messages.Messages.NewModelFilePage_new_diagram_category_needs_specific_extension;
+ String message2 = NLS.bind(org.eclipse.papyrus.uml.diagram.wizards.messages.Messages.NewModelFilePage_diagram_file_was_renamed, oldFileName, newFileName);
+ String message = message1 + message2;
+ Status resultStatus = new Status(IStatus.INFO, Activator.PLUGIN_ID, message);
+
+ String errorMessage = getErrorMessage();
+ if (errorMessage != null) {
+ resultStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMessage);
+ }
+ return resultStatus;
+ }
+ return Status.OK_STATUS;
+ }
+
+ void setNewResourceName(String newName) {
+ nameText.setText(newName.trim());
+ }
+
+ void validatePage() {
+ newModelResourceURI = null;
+ setMessage(null, NONE);
+ setPageComplete(true);
+
+ String folder = folderText.getText().trim();
+ if (Strings.isNullOrEmpty(folder)) {
+ setPageComplete(false);
+ return;
+ }
+
+ String[] segments = getSegments(folder);
+ CDOCheckout checkout = CDOExplorerUtil.getCheckoutManager().getCheckoutByLabel(segments[0]);
+ if (checkout == null) {
+ setMessage(NLS.bind(Messages.NewModelPage_16, segments[0]), ERROR);
+ setPageComplete(false);
+ return;
+ }
+
+ CDOView view = checkout.getView();
+ String path = "";
+ SegmentType segmentType = SegmentType.FOLDER; // The checkout is treated like a folder.
+
+ for (int i = 1; i < segments.length; i++) {
+ String segment = segments[i];
+ path += "/";
+ path += segment;
+
+ segmentType = SegmentType.of(view, path);
+ if (segmentType == SegmentType.OTHER) {
+ setMessage(Messages.NewModelPage_20, ERROR);
+ setPageComplete(false);
+ return;
+ }
+ }
+
+ String name = getNewResourceName();
+ if (Strings.isNullOrEmpty(name)) {
+ setMessage(Messages.NewModelPage_17, ERROR);
+ setPageComplete(false);
+ return;
+ }
+
+ if (segmentType != SegmentType.MISSING) {
+ String fullPath = path + "/" + name;
+ if (SegmentType.of(view, fullPath) != SegmentType.MISSING) {
+ setMessage(NLS.bind(Messages.NewModelPage_18, fullPath), ERROR);
+ setPageComplete(false);
+ return;
+ }
+ }
+
+ newModelResourceURI = checkout.createResourceURI(path).appendSegment(name);
+
+ if (segmentType == SegmentType.MISSING) {
+ setMessage(Messages.NewModelPage_19, WARNING);
+ }
+ }
+
+ private String[] getSegments(String folder) {
+ while (folder.startsWith("/")) {
+ folder = folder.substring(1);
+ }
+
+ while (folder.endsWith("/")) {
+ folder = folder.substring(0, folder.length() - 1);
+ }
+
+ return folder.split("/");
+ }
+
+ private String getExtension() {
+ String result = null;
+ String name = getNewResourceName();
+
+ if (name != null) {
+ // the proper extension is whatever follows the *last* '.',
+ // but for our purposes we need e.g. "profile.uml" to be
+ // an extension
+ int dot = name.indexOf('.');
+ if (dot >= 0) {
+ result = name.substring(dot + 1);
+ }
+ }
+
+ return result;
+ }
+
+ private void setSelection(IStructuredSelection selection) {
+ selectedElement = null;
+
+ if (!selection.isEmpty()) {
+ Object element = selection.getFirstElement();
+ if (element instanceof CDOElement) {
+ element = ((CDOElement) element).getDelegate();
+ }
+
+ if (element instanceof CDOCheckout) {
+ selectedElement = element;
+ } else if (element instanceof CDOResourceLeaf) {
+ selectedElement = ((CDOResourceLeaf) element).getFolder();
+ } else if (element instanceof CDOResourceFolder) {
+ selectedElement = (CDOResourceFolder) element;
+ } else if (element instanceof EObject) {
+ Resource resource = ((EObject) element).eResource();
+ if (resource instanceof CDOResource) {
+ selectedElement = ((CDOResource) resource).getFolder();
+ }
+ }
+ }
+ }
+
+ private void updateFolderText() {
+ if (!synchronizingFolderSelection) {
+ synchronizingFolderSelection = true;
+
+ try {
+ if (selectedElement == null) {
+ folderText.setText(""); //$NON-NLS-1$
+ } else {
+ StringBuilder builder = new StringBuilder();
+ for (Object node : getSelectedSegments()) {
+ builder.append('/');
+ builder.append(CDOExplorerUtil.getName(node));
+ }
+
+ String path = builder.toString();
+ folderText.setText(path);
+ }
+ } finally {
+ synchronizingFolderSelection = false;
+ }
+ }
+ }
+
+ private void revealSelectedElement() {
+ if (selectedElement != null) {
+ List<Object> segments = getSelectedSegments();
+ for (int i = 0; i < segments.size() - 1; i++) {
+ Object segment = segments.get(i);
+ folderViewer.setExpandedState(segment, true);
+ }
+
+ selectedElementRevealed = true;
+ folderViewer.setSelection(new StructuredSelection(selectedElement), true);
+ }
+ }
+
+ private List<Object> getSelectedSegments() {
+ List<Object> segments = new ArrayList<Object>();
+ fillSegments(segments, selectedElement);
+ return segments;
+ }
+
+ private void fillSegments(List<Object> segments, Object element) {
+ if (element instanceof CDOCheckout) {
+ segments.add(element);
+ return;
+ }
+
+ if (element instanceof CDOResourceFolder) {
+ CDOResourceFolder folder = (CDOResourceFolder) element;
+
+ Adapter adapter = EcoreUtil.getAdapter(folder.eAdapters(), CDOCheckout.class);
+ if (adapter != null) {
+ fillSegments(segments, adapter);
+ } else {
+ Object parent = folder.getFolder();
+ if (parent == null) {
+ parent = EcoreUtil.getAdapter(folder.cdoView().getRootResource().eAdapters(), CDOCheckout.class);
+ }
+
+ fillSegments(segments, parent);
+ }
+ }
+
+ segments.add(element);
+ }
+
+ private EList<EObject> getChildrenOfSelectedElement() {
+ if (selectedElement instanceof CDOCheckout) {
+ CDOCheckout checkout = (CDOCheckout) selectedElement;
+ return checkout.getRootObject().eContents();
+ }
+
+ if (selectedElement instanceof CDOResourceFolder) {
+ CDOResourceFolder folder = (CDOResourceFolder) selectedElement;
+ return folder.eContents();
+ }
+
+ return ECollections.emptyEList();
+ }
+
+ private String getUniqueName(String extension) {
+ Set<String> names = new HashSet<String>();
+ for (EObject eObject : getChildrenOfSelectedElement()) {
+ if (eObject instanceof CDOResourceNode) {
+ CDOResourceNode node = (CDOResourceNode) eObject;
+ String name = node.getName();
+ if (name.startsWith(resourceType)) {
+ names.add(name);
+ }
+ }
+ }
+
+ for (int i = 1; i < Integer.MAX_VALUE; i++) {
+ String name = resourceType + (i > 1 ? i : "") + "." + extension;
+ if (!names.contains(name)) {
+ return name;
+ }
+ }
+
+ throw new IllegalStateException("Too many children");
+ }
+
+ /**
+ * @author Stepper
+ */
+ private enum SegmentType {
+ MISSING, FOLDER, OTHER;
+
+ public static SegmentType of(CDOView view, String path) {
+ CDOResourceNode resourceNode;
+ try {
+ resourceNode = view.getResourceNode(path);
+ if (resourceNode != null) {
+ if (resourceNode instanceof CDOResourceFolder) {
+ return SegmentType.FOLDER;
+ }
+
+ return SegmentType.OTHER;
+ }
+ } catch (Exception ex) {
+ //$FALL-THROUGH$
+ }
+
+ return SegmentType.MISSING;
+ }
+
+ private static SegmentType of(CDOResourceNode resourceNode) {
+ if (resourceNode == null) {
+ return SegmentType.MISSING;
+ }
+
+ if (resourceNode instanceof CDOResourceFolder) {
+ return SegmentType.FOLDER;
+ }
+
+ return SegmentType.OTHER;
+ }
+ }
+}

Back to the top