Skip to content

Commit

Permalink
[471] Init the dialog with current image path
Browse files Browse the repository at this point in the history
When the selected DDiagramElement already has a workspace image, init
the image dialog with current image path, expand the tree and and select
the image in gallery.

Bug: #471
Signed-off-by: Maxime Porhel <[email protected]>
  • Loading branch information
mPorhel committed Nov 26, 2024
1 parent 1566719 commit 03aee7f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public class ImageSelectionDialog extends Dialog {
*/
private Text imagePathText;

private boolean displayImagePaths;

/**
* Create a new instance of {@link ImageSelectionDialog}.
*
Expand All @@ -130,8 +132,10 @@ public class ImageSelectionDialog extends Dialog {
* if true there is only the close button instead of OK/Cancel
* @param currentImagePath
* the path to the image as it is serialized in the model
* @param displayImagePaths
* if true, display the current and new selected image path and a message if the image is not found.
*/
public ImageSelectionDialog(Shell parentShell, EObject contextObject, boolean onlyCloseButton, String currentImagePath) {
public ImageSelectionDialog(Shell parentShell, EObject contextObject, boolean onlyCloseButton, String currentImagePath, boolean displayImagePaths) {
super(parentShell);
this.title = Messages.ImageSelectionDialog_title;
this.root = ResourcesPlugin.getWorkspace().getRoot();
Expand All @@ -143,6 +147,7 @@ public ImageSelectionDialog(Shell parentShell, EObject contextObject, boolean on
if (currentImagePath != null) {
this.currentImagePath = URI.decode(currentImagePath.replace("\\", SLASH)); //$NON-NLS-1$
}
this.displayImagePaths = displayImagePaths;
this.contextObject = contextObject;
}

Expand Down Expand Up @@ -352,7 +357,7 @@ private Object computeImageWithSameName(Object[] elements, String imageName) {
}

private void createImagePathComposite(Composite parent) {
if (currentImagePath != null) {
if (currentImagePath != null && displayImagePaths) {
Composite imagePathContainer = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
imagePathContainer.setLayout(gridLayout);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2022 THALES GLOBAL SERVICES.
* Copyright (c) 2012, 2024 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -39,6 +39,22 @@ enum SelectionMode {
MULTI_SELECTION
};

/**
* Get the selected image paths.
*
* @param eObject
* the {@link EObject} used to associate the image with
* @param selectionMode
* the selectionMode
* @param currentSelection
* the current image path.
* @param displayImagePaths
* if true, the dialog will display the current and new selected image path and a message if the image is
* not found.
* @return a non null list of the selected image paths
*/
List<String> selectImages(EObject eObject, SelectionMode selectionMode, String currentSelection, boolean displayImagePaths);

/**
* Get the selected image paths.
*
Expand All @@ -51,7 +67,9 @@ enum SelectionMode {
* and a message if the image is not found.
* @return a non null list of the selected image paths
*/
List<String> selectImages(EObject eObject, SelectionMode selectionMode, String currentSelection);
default List<String> selectImages(EObject eObject, SelectionMode selectionMode, String currentSelection) {
return selectImages(eObject, selectionMode, currentSelection, true);
}

/**
* Get the selected image paths.
Expand All @@ -62,6 +80,8 @@ enum SelectionMode {
* the selectionMode
* @return a non null list of the selected image paths
*/
List<String> selectImages(EObject eObject, SelectionMode selectionMode);
default List<String> selectImages(EObject eObject, SelectionMode selectionMode) {
return selectImages(eObject, selectionMode, null);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2022 THALES GLOBAL SERVICES.
* Copyright (c) 2012, 2024 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -28,11 +28,11 @@
public class WorkspaceImageSelector implements ImageSelector {

@Override
public List<String> selectImages(EObject eObject, ImageSelector.SelectionMode selectionMode, String currentImagePath) {
public List<String> selectImages(EObject eObject, ImageSelector.SelectionMode selectionMode, String currentImagePath, boolean displayImagePaths) {
String imagePath = null;
Shell activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();

ImageSelectionDialog dialog = new ImageSelectionDialog(activeShell, eObject, false, currentImagePath);
ImageSelectionDialog dialog = new ImageSelectionDialog(activeShell, eObject, false, currentImagePath, displayImagePaths);
if (dialog.open() == Window.OK) {
imagePath = dialog.getImagePath();
}
Expand All @@ -43,9 +43,4 @@ public List<String> selectImages(EObject eObject, ImageSelector.SelectionMode se
}
}

@Override
public List<String> selectImages(EObject eObject, SelectionMode selectionMode) {
return selectImages(eObject, selectionMode, null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void run() {
if (basicLabelStyle instanceof WorkspaceImage img) {
workspacePath = img.getWorkspacePath();
}
List<String> imagePaths = imageSelector.selectImages(basicLabelStyle, ImageSelector.SelectionMode.MONO_SELECTION, workspacePath);
List<String> imagePaths = imageSelector.selectImages(basicLabelStyle, ImageSelector.SelectionMode.MONO_SELECTION, workspacePath, false);
if (imagePaths.size() == 1) {
if (imagePaths.get(0).equals(ImageSelectionDialog.NO_IMAGE_PATH_TEXT)) {
WorkspaceImageHelper.INSTANCE.resetStyle(basicLabelStyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.WorkspaceImage;
import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery;
import org.eclipse.sirius.diagram.business.api.query.EObjectQuery;
import org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog;
Expand Down Expand Up @@ -417,7 +418,11 @@ protected void setBackgroundImage(final SelectionEvent event) {
ImageSelector imageSelector = ImageSelectorService.INSTANCE.getImageSelector();
List<BasicLabelStyle> styles = getStyles();
for (BasicLabelStyle basicLabelStyle : styles) {
List<String> imagePaths = imageSelector.selectImages(basicLabelStyle, ImageSelector.SelectionMode.MONO_SELECTION);
String workspacePath = null;
if (basicLabelStyle instanceof WorkspaceImage img) {
workspacePath = img.getWorkspacePath();
}
List<String> imagePaths = imageSelector.selectImages(basicLabelStyle, ImageSelector.SelectionMode.MONO_SELECTION, workspacePath, false);
if (imagePaths.size() == 1) {
if (imagePaths.get(0).equals(ImageSelectionDialog.NO_IMAGE_PATH_TEXT)) {
WorkspaceImageHelper.INSTANCE.resetStyle(basicLabelStyle);
Expand Down
14 changes: 14 additions & 0 deletions plugins/org.eclipse.sirius.doc/doc/Release_Notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,20 @@ <h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in
<code>org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.isResetImage()</code> and
<code>org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.setResetImage(boolean)</code> have been added to handle the new &#8220;Reset Image Style&#8221; feature in the related dialog.
</li>
<li><span class="label label-success">Added</span>
<code>org.eclipse.sirius.diagram.ui.business.api.image.WorkspaceImageHelper.resetStyle(BasicLabelStyle)</code> has been added to reset the WorkspaceImage style assigned to a DDiagramElement, while preserving all other style modifications. In other words, the workspacePath feature is reset.
</li>
<li><span class="label label-success">Added</span>
<code>org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.isResetImage()</code> and
<code>org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.setResetImage(boolean)</code> have been added to handle the new &#8220;Reset Image Style&#8221; feature in the related dialog.
</li>
<li><span class="label label-success">Added</span> The method
<code>org.eclipse.sirius.diagram.ui.business.api.image.ImageSelector.selectImages(EObject, SelectionMode, String, boolean)</code> has been added to de-corelate the display of current/new image path field from the present of a value to the
<code>currentSelection</code> parameter. Default implementations of the other
<code>ImageSelector.selectImages</code> methods have been added in the interface to match previous behavior for callers of those methods. The
<code>org.eclipse.sirius.diagram.ui.business.api.image.WorkspaceImageSelector.selectImages(EObject, SelectionMode, String, boolean)</code> has been removed in favor of the default implementation of the method in
<code>ImageSelector</code>.
</li>
</ul>
<h4 id="Changesinorg.eclipse.sirius.tests.support">Changes in
<code>org.eclipse.sirius.tests.support</code>
Expand Down
4 changes: 4 additions & 0 deletions plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ h3. User-Visible Changes

* <span class="label label-success">Added</span> In the @ImageSelectionDialog@, a new feature has been added to reset the WorkspaceImage assigned to a DDiagramElement. Before this improvement, it was necessary to use the “Reset style properties to default values” button, but this also affected all other style modifications. This new button in the dialog resets only the WorkspaceImage style to the style of the element as defined in the Viewpoint Specification Model. </br> !{width: 500px}user/diagrams/images/selectImageDialog_resetImage.png!


h3. Developer-Visible Changes

h4. Changes in @org.eclipse.sirius.diagram.ui@

* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.image.WorkspaceImageHelper.resetStyle(BasicLabelStyle)@ has been added to reset the WorkspaceImage style assigned to a DDiagramElement, while preserving all other style modifications. In other words, the workspacePath feature is reset.
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.isResetImage()@ and @org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.setResetImage(boolean)@ have been added to handle the new "Reset Image Style" feature in the related dialog.
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.image.WorkspaceImageHelper.resetStyle(BasicLabelStyle)@ has been added to reset the WorkspaceImage style assigned to a DDiagramElement, while preserving all other style modifications. In other words, the workspacePath feature is reset.
* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.isResetImage()@ and @org.eclipse.sirius.diagram.ui.business.api.image.ImageSelectionDialog.setResetImage(boolean)@ have been added to handle the new "Reset Image Style" feature in the related dialog.
* <span class="label label-success">Added</span> The method @org.eclipse.sirius.diagram.ui.business.api.image.ImageSelector.selectImages(EObject, SelectionMode, String, boolean)@ has been added to de-corelate the display of current/new image path field from the present of a value to the @currentSelection@ parameter. Default implementations of the other @ImageSelector.selectImages@ methods have been added in the interface to match previous behavior for callers of those methods. The @org.eclipse.sirius.diagram.ui.business.api.image.WorkspaceImageSelector.selectImages(EObject, SelectionMode, String, boolean)@ has been removed in favor of the default implementation of the method in @ImageSelector@.

h4. Changes in @org.eclipse.sirius.tests.support@

Expand Down

0 comments on commit 03aee7f

Please sign in to comment.