diff options
author | Benoit Maggi | 2017-09-19 14:57:59 +0000 |
---|---|---|
committer | Benoit Maggi | 2017-09-22 14:25:59 +0000 |
commit | c0b4ee0c137174290baf166e7ef3a7966ea5da29 (patch) | |
tree | dd0aeda7dbaed9bdd10b2dd5b2638861b6d570e5 /plugins | |
parent | ce44e3ba2d983ea0f071ca5e83bb79cc07b6af7c (diff) | |
download | org.eclipse.papyrus-c0b4ee0c137174290baf166e7ef3a7966ea5da29.tar.gz org.eclipse.papyrus-c0b4ee0c137174290baf166e7ef3a7966ea5da29.tar.xz org.eclipse.papyrus-c0b4ee0c137174290baf166e7ef3a7966ea5da29.zip |
Bug 518307 - [Control Mode] Warning when resource already exist
- check if the resource already exist
- use diagnostic to provide a simple way to evaluate
- fix some quality warnings
Change-Id: I9fb99d532f3efc7470864dbd9331b26387ad88eb
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins')
12 files changed, 71 insertions, 44 deletions
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF index 9907c056461..0d9eebe349a 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/META-INF/MANIFEST.MF @@ -2,10 +2,13 @@ Manifest-Version: 1.0 Export-Package: org.eclipse.papyrus.infra.services.controlmode,
org.eclipse.papyrus.infra.services.controlmode.commands,
org.eclipse.papyrus.infra.services.controlmode.handler,
- org.eclipse.papyrus.infra.services.controlmode.messages,
+ org.eclipse.papyrus.infra.services.controlmode.helper.advice,
org.eclipse.papyrus.infra.services.controlmode.internal.handler;x-internal:=true,
org.eclipse.papyrus.infra.services.controlmode.internal.ui;x-internal:=true,
+ org.eclipse.papyrus.infra.services.controlmode.listener,
+ org.eclipse.papyrus.infra.services.controlmode.messages,
org.eclipse.papyrus.infra.services.controlmode.participants,
+ org.eclipse.papyrus.infra.services.controlmode.service,
org.eclipse.papyrus.infra.services.controlmode.ui,
org.eclipse.papyrus.infra.services.controlmode.util
Require-Bundle: org.eclipse.emf.edit.ui;bundle-version="[2.12.0,3.0.0)";visibility:=reexport,
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/IControlModeManager.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/IControlModeManager.java index e8680b11ef0..0cb31014acd 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/IControlModeManager.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/IControlModeManager.java @@ -23,7 +23,6 @@ import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.resource.ShardResourceHelper;
-import org.eclipse.papyrus.infra.services.controlmode.participants.IControlCommandApprover;
/**
* A control manger is able to compute a command in order to control or uncontrol an element from a {@link ControlModeRequest}.
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java index 84a2bf1673c..36a6ddcd3f9 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/commands/InitializeSashCommand.java @@ -27,7 +27,6 @@ import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModel; import org.eclipse.papyrus.infra.core.resource.sasheditor.SashModelUtils; import org.eclipse.papyrus.infra.core.sashwindows.di.AbstractPanel; import org.eclipse.papyrus.infra.core.sashwindows.di.PageRef; -import org.eclipse.papyrus.infra.core.sashwindows.di.SashModel; import org.eclipse.papyrus.infra.core.sashwindows.di.SashPanel; import org.eclipse.papyrus.infra.core.sashwindows.di.SashWindowsMngr; import org.eclipse.papyrus.infra.core.sashwindows.di.TabFolder; diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/handler/ControlCommandHandler.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/handler/ControlCommandHandler.java index 3a9e5211b94..3a3b497edd3 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/handler/ControlCommandHandler.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/handler/ControlCommandHandler.java @@ -92,7 +92,7 @@ public class ControlCommandHandler extends AbstractHandler { ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection instanceof IStructuredSelection) { - if (selection == null || selection.isEmpty() || ((IStructuredSelection) selection).size() > 1) { + if (selection.isEmpty() || ((IStructuredSelection) selection).size() > 1) { NotificationBuilder.createInfoPopup(EMPTY_SELECTION_MESSAGE).run(); return null; } diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/messages/messages.properties b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/messages/messages.properties index 71be1ed9c4e..9141463466a 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/messages/messages.properties +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/messages/messages.properties @@ -9,7 +9,7 @@ # Contributors: # Gabriel Pascual (ALL4TEC) - Initial API and implementation # Christian W. Damus - bug 497865 -# +# Benoit Maggi (CEA LIST) - bug 518307 AbstractControlResourceCommand.object.error=EObject not link to resource set AbstractSatelliteResourceParticipant.command.title={0} Composite Command [ {1} ] @@ -44,6 +44,7 @@ ControlModeManager.uncontrol.command.pre.title=UnControl Command [ Pre commands] CreateControlResource.command.title=Create a control resource CreateControlResource.modelset.error=Unable to get model set CreateControlResource.resource.error=Unable to create new resource to control +CreateModelFragmentDialog.dialog.warning.alreadyexist=Already existing resource CreateModelFragmentDialog.dialog.title=Submodel Resource CreateModelFragmentDialog.submodel.checkbox=Create an independent submodel resource LabelHelper.label.error=Error in getting correct label diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandApprover.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandApprover.java index 2da187173ad..37b89317e0f 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandApprover.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandApprover.java @@ -14,7 +14,6 @@ package org.eclipse.papyrus.infra.services.controlmode.participants; import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.emf.common.util.DiagnosticChain; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandParticipant.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandParticipant.java index e9f6e8ede2c..853052c3d8d 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandParticipant.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlCommandParticipant.java @@ -14,7 +14,6 @@ package org.eclipse.papyrus.infra.services.controlmode.participants;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlModeParticipant.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlModeParticipant.java index 29164e73528..8a05d79f8c2 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlModeParticipant.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IControlModeParticipant.java @@ -10,9 +10,6 @@ ******************************************************************************/
package org.eclipse.papyrus.infra.services.controlmode.participants;
-import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
-
-
/**
* Represent a element which participate to creation of a control/Uncontrol command
*
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IUncontrolCommandParticipant.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IUncontrolCommandParticipant.java index 4bfaacadce7..12e65bdad7a 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IUncontrolCommandParticipant.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/participants/IUncontrolCommandParticipant.java @@ -14,7 +14,6 @@ package org.eclipse.papyrus.infra.services.controlmode.participants;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest;
/**
diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/CreateModelFragmentDialog.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/CreateModelFragmentDialog.java index 7defb515031..2c58e1ce1ce 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/CreateModelFragmentDialog.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/CreateModelFragmentDialog.java @@ -1,6 +1,6 @@ /******************************************************************************* - * Copyright (c) 2006, 2016 Anyware Technologies. All rights reserved. This program, Christian W. Damus, and others - * and the accompanying materials are made available under the terms of the + * Copyright (c) 2006, 2016-2017 Anyware Technologies 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 * @@ -8,21 +8,29 @@ * Jacques Lescot (Anyware Technologies) - Initial API and implementation * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 436947 * Christian W. Damus - bug 497865 + * Benoit Maggi (CEA LIST) - bug 518307 ******************************************************************************/ package org.eclipse.papyrus.infra.services.controlmode.ui; +import java.util.Collections; + import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.ui.dialogs.ResourceDialog; import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog; +import org.eclipse.emf.common.util.BasicDiagnostic; import org.eclipse.emf.common.util.Diagnostic; 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.resource.impl.ResourceSetImpl; import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.jface.dialogs.DialogSettings; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.fieldassist.ControlDecoration; +import org.eclipse.jface.fieldassist.FieldDecoration; +import org.eclipse.jface.fieldassist.FieldDecorationRegistry; import org.eclipse.papyrus.infra.services.controlmode.ControlModeManager; import org.eclipse.papyrus.infra.services.controlmode.ControlModePlugin; import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; @@ -38,9 +46,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; /** - * Dialog that will ask the user the target URI for th new resource holding the new controlled element - * - * @author adaussy + * Dialog that will ask the user the target URI for the new resource holding the new controlled element * */ public class CreateModelFragmentDialog extends ResourceDialog { @@ -60,6 +66,7 @@ public class CreateModelFragmentDialog extends ResourceDialog { private Button shardButton; private boolean createShard; + private ControlDecoration controlDecoration; /** * The constructor @@ -79,8 +86,7 @@ public class CreateModelFragmentDialog extends ResourceDialog { * @since 1.3 */ public CreateModelFragmentDialog(Shell parent, EObject objectToControl, String defaultName) { - this(parent, objectToControl.eResource(), defaultName); // $NON-NLS-1$ - + this(parent, objectToControl.eResource(), defaultName); this.objectToControl = objectToControl; } @@ -93,7 +99,7 @@ public class CreateModelFragmentDialog extends ResourceDialog { IFile file = null; String path = URI.createURI(computeDefaultURI()).lastSegment(); file = WorkspaceResourceDialog.openNewFile(getShell(), null, null, path != null ? new Path(path) : null, null); - if (file != null) { + if (file != null) { uriField.setText(URI.createPlatformResourceURI(file.getFullPath().toString(), true).toString()); } } @@ -112,12 +118,11 @@ public class CreateModelFragmentDialog extends ResourceDialog { protected Control createContents(Composite parent) { Control result = super.createContents(parent); this.uriField.setText(computeDefaultURI()); - // And the rest of the dialog initialization loadDialogState(); // Is the sub-model unit option available? - if ((objectToControl != null) && !ControlModeManager.getInstance().canCreateSubmodel(objectToControl)) { + if (objectToControl != null && !ControlModeManager.getInstance().canCreateSubmodel(objectToControl)) { // We can only create a shard resource shardButton.setSelection(false); shardButton.setEnabled(false); @@ -126,7 +131,6 @@ public class CreateModelFragmentDialog extends ResourceDialog { // Initial validation validateDialog(); - return result; } @@ -154,16 +158,15 @@ public class CreateModelFragmentDialog extends ResourceDialog { @Override public void widgetSelected(SelectionEvent e) { createShard = !shardButton.getSelection(); - validateDialog(); } }); - + uriField.addModifyListener(__ -> validateDialog()); - + controlDecoration = new ControlDecoration(uriField, SWT.TOP | SWT.LEFT); // This is guaranteed by contract with subclasses to be the first child Control buttonComposite = superContents[0]; - result.setTabList(new Control[] { uriField, buttonComposite, shardButton }); + result.setTabList(new Control[] {uriField, buttonComposite, shardButton }); return result; } @@ -178,11 +181,8 @@ public class CreateModelFragmentDialog extends ResourceDialog { */ @Override protected boolean processResources() { - URI uri = URI.createURI(getURIText()); - this.uri = uri; - + this.uri = URI.createURI(getURIText()); saveDialogState(); - return true; } @@ -249,22 +249,54 @@ public class CreateModelFragmentDialog extends ResourceDialog { * @since 1.3 */ protected boolean validateDialog() { + Diagnostic diagnostic = diagnosticDialog(); + switch (diagnostic.getSeverity()) { + case Diagnostic.ERROR: + FieldDecoration error = FieldDecorationRegistry.getDefault() + .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR); + controlDecoration.setImage(error.getImage()); + controlDecoration.showHoverText(diagnostic.getMessage()); + controlDecoration.setDescriptionText(diagnostic.getMessage()); + controlDecoration.show(); + getButton(IDialogConstants.OK_ID).setEnabled(false); + break; + case Diagnostic.WARNING: + FieldDecoration warning = FieldDecorationRegistry.getDefault() + .getFieldDecoration(FieldDecorationRegistry.DEC_WARNING); + controlDecoration.setImage(warning.getImage()); + controlDecoration.showHoverText(diagnostic.getMessage()); + controlDecoration.setDescriptionText(diagnostic.getMessage()); + controlDecoration.show(); + getButton(IDialogConstants.OK_ID).setEnabled(true); + break; + case Diagnostic.OK: + default: + controlDecoration.hide(); + getButton(IDialogConstants.OK_ID).setEnabled(true); + break; + } + + return diagnostic.getSeverity() != Diagnostic.ERROR ; + } + + /** + * @return diagnostic of the dialog + */ + protected Diagnostic diagnosticDialog() { URI uri = getURIs().stream().findAny().orElse(null); - boolean result = uri != null; - + Diagnostic diagnostic = Diagnostic.OK_INSTANCE; // Can only create requests for validation if we have an object and a URI - if ((objectToControl != null) && (uri != null)) { + if (uri != null && objectToControl != null) { ControlModeRequest request = ControlModeRequest.createUIControlModelRequest( TransactionUtil.getEditingDomain(objectToControl), objectToControl, uri); - - Diagnostic diagnostic = ControlModeManager.getInstance().approveRequest(request); - result = diagnostic.getSeverity() < Diagnostic.ERROR; + diagnostic = ControlModeManager.getInstance().approveRequest(request); } - - getButton(IDialogConstants.OK_ID).setEnabled(result); - - return result; + if (Diagnostic.OK == diagnostic.getSeverity() && new ResourceSetImpl().getURIConverter().exists(uri, Collections.emptyMap())) { + diagnostic = new BasicDiagnostic(Diagnostic.WARNING, ControlModePlugin.PLUGIN_ID, 0, Messages.getString("CreateModelFragmentDialog.dialog.warning.alreadyexist"), null); //$NON-NLS-1$ + } + return diagnostic; } + } diff --git a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/IControlModeFragmentDialogProvider.java b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/IControlModeFragmentDialogProvider.java index 54c36d77363..67bc43cc21f 100644 --- a/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/IControlModeFragmentDialogProvider.java +++ b/plugins/infra/services/org.eclipse.papyrus.infra.services.controlmode/src/org/eclipse/papyrus/infra/services/controlmode/ui/IControlModeFragmentDialogProvider.java @@ -22,7 +22,6 @@ import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.infra.core.resource.ModelSet; import org.eclipse.papyrus.infra.services.controlmode.ControlModeRequest; import org.eclipse.swt.widgets.Shell; diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java index 70d21024c07..7ce6c013c78 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/NewModelFilePage.java @@ -272,7 +272,7 @@ public class NewModelFilePage extends WizardNewFileCreationPage implements INewP String existingModelName = ""; for (String existingName : getExistingNames()) { - if (existingName.toLowerCase().equals(getFileName().toLowerCase())) { + if (existingName.equalsIgnoreCase(getFileName())) { canFlip = false; existingModelName = existingName; break; @@ -299,7 +299,7 @@ public class NewModelFilePage extends WizardNewFileCreationPage implements INewP * The list of the names */ public Collection<String> getExistingNames() { - Collection<String> result = new LinkedList<String>(); + Collection<String> result = new LinkedList<>(); try { IResource rootResource = ResourcesPlugin.getWorkspace().getRoot().findMember(getContainerFullPath()); @@ -326,7 +326,7 @@ public class NewModelFilePage extends WizardNewFileCreationPage implements INewP * @return */ public Collection<String> getMembersNames(IResource[] membersArray) { - Collection<String> membersList = new LinkedList<String>(); + Collection<String> membersList = new LinkedList<>(); for (Iterator<IResource> arrayIter = Arrays.asList(membersArray).iterator(); arrayIter.hasNext();) { IResource iResource = arrayIter.next(); membersList.add(iResource.getName()); |