Skip to content
Snippets Groups Projects
Commit 05970682 authored by Tiziano Munaro's avatar Tiziano Munaro
Browse files

Merge remote-tracking branch 'origin/master' into 4319

parents 7072990f 9893c900
No related branches found
No related tags found
1 merge request!2054319
Pipeline #39202 failed
Showing
with 512 additions and 288 deletions
...@@ -34,3 +34,9 @@ ...@@ -34,3 +34,9 @@
[submodule "org.fortiss.variability/.settings"] [submodule "org.fortiss.variability/.settings"]
path = org.fortiss.variability/.settings path = org.fortiss.variability/.settings
url = https://git.fortiss.org/af3/plugin-settings.git url = https://git.fortiss.org/af3/plugin-settings.git
[submodule "org.fortiss.tooling.ext.reuse/.settings"]
path = org.fortiss.tooling.ext.reuse/.settings
url = https://git.fortiss.org/af3/plugin-settings.git
[submodule "org.fortiss.tooling.ext.reuse.ui/.settings"]
path = org.fortiss.tooling.ext.reuse.ui/.settings
url = https://git.fortiss.org/af3/plugin-settings.git
...@@ -7,7 +7,8 @@ Bundle-Activator: org.fortiss.tooling.base.ui.ToolingBaseUIActivator ...@@ -7,7 +7,8 @@ Bundle-Activator: org.fortiss.tooling.base.ui.ToolingBaseUIActivator
Require-Bundle: org.fortiss.tooling.base;bundle-version="2.23.0";visibility:=reexport, Require-Bundle: org.fortiss.tooling.base;bundle-version="2.23.0";visibility:=reexport,
org.fortiss.tooling.kernel.ui;bundle-version="2.23.0";visibility:=reexport, org.fortiss.tooling.kernel.ui;bundle-version="2.23.0";visibility:=reexport,
org.eclipse.swt, org.eclipse.swt,
org.fortiss.tooling.common.ui org.fortiss.tooling.common.ui,
org.fortiss.tooling.ext.reuse
Bundle-ActivationPolicy: lazy Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-Vendor: fortiss GmbH Bundle-Vendor: fortiss GmbH
......
AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN AbstractNameEditingSupport.java c57336a0e0da18711a1610ca667dfea76728807f GREEN
ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN ActionUtils.java 322f43d4f92f992daef8ac88eb0f9197c840c89b GREEN
ContextMenuUtils.java a55ceed42f2eb88ba263a6fbcb394ddb80b1eda0 GREEN ContextMenuUtils.java 75af4d1e995f4baba451e608d1a4716f13388dbd GREEN
EllipseLayoutUIUtils.java 0af2cfc038661828b1bb8c51c0a3816d453e8313 GREEN EllipseLayoutUIUtils.java 0af2cfc038661828b1bb8c51c0a3816d453e8313 GREEN
FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN FXDNDUtils.java 6ce94e239e68f9e2b3cc0524b072606f4a120076 GREEN
FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN FontUtils.java a167a05bdaa8da9853705cc5134f30f6d81bc9f2 GREEN
......
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2019 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -15,9 +15,13 @@ ...@@ -15,9 +15,13 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.base.ui.utils; package org.fortiss.tooling.base.ui.utils;
import static java.util.Collections.reverse;
import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint; import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getNameOfFirstRelatedLibrary;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.isCorrectReuseElement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EObject;
...@@ -62,7 +66,6 @@ public final class ContextMenuUtils { ...@@ -62,7 +66,6 @@ public final class ContextMenuUtils {
IElementCompositionContext context, boolean onlyForEditedObject) { IElementCompositionContext context, boolean onlyForEditedObject) {
IPrototypeService pers = IPrototypeService.getInstance(); IPrototypeService pers = IPrototypeService.getInstance();
IElementCompositorService ecs = IElementCompositorService.getInstance(); IElementCompositorService ecs = IElementCompositorService.getInstance();
ICommandStackService css = ICommandStackService.getInstance();
IModelEditor<EObject> activeEditor = IModelEditor<EObject> activeEditor =
IModelEditorBindingService.getInstance().getActiveEditor(); IModelEditorBindingService.getInstance().getActiveEditor();
boolean isMenuForEditedObject = boolean isMenuForEditedObject =
...@@ -70,31 +73,94 @@ public final class ContextMenuUtils { ...@@ -70,31 +73,94 @@ public final class ContextMenuUtils {
List<MenuItem> result = new ArrayList<>(); List<MenuItem> result = new ArrayList<>();
Menu newMenu = new Menu("New ..."); Menu newMenu = new Menu("New ...");
List<Prototype> protos = pers.getComposablePrototypes(target.getClass()); Menu reuseMenu = new Menu("Reuse ...");
for(Prototype p : protos) {
EObject prototypeCopy = p.getPrototypeCopy(); List<Prototype> prototypes = pers.getComposablePrototypes(target.getClass());
List<Prototype> prototypesForNewMenu = new ArrayList<>();
for(Prototype prototype : prototypes) {
EObject prototypeCopy = prototype.getPrototypeCopy();
// If the context menu is created for the currently edited object, offer all composable // If the context menu is created for the currently edited object, offer all composable
// elements. Otherwise (i.e., if context menu is created for a structural element within // elements. Otherwise (i.e., if context menu is created for a structural element within
// the currently edited object), offer only (composable) connectors. // the currently edited object), offer only (composable) connectors.
if((!onlyForEditedObject || isMenuForEditedObject || if((!onlyForEditedObject || isMenuForEditedObject ||
prototypeCopy instanceof IConnector) && prototypeCopy instanceof IConnector) &&
ecs.canCompose(target, prototypeCopy, context)) { ecs.canCompose(target, prototypeCopy, context)) {
MenuItem mi = new MenuItem(p.getName()); if(isCorrectReuseElement(prototypeCopy)) {
mi.setOnAction(evt -> { MenuItem menuItem = createMenuItemForComposableElement(prototypeCopy, target,
css.runAsCommand(target, () -> { context, prototype.getName());
ecs.compose(target, prototypeCopy, context); String libraryName = getNameOfFirstRelatedLibrary(prototypeCopy);
}); menuItem.setText("[" + libraryName + "] " + prototype.getName());
}); // To prevent that underscores are swallowed up:
newMenu.getItems().add(mi); menuItem.setMnemonicParsing(false);
reuseMenu.getItems().add(menuItem);
} else {
prototypesForNewMenu.add(prototype);
}
} }
} }
// Sort first by priority and then by name (lexicographical).
prototypesForNewMenu.sort(new Comparator<Prototype>() {
@Override
public int compare(Prototype prototype1, Prototype prototype2) {
int result = prototype1.getPriority() - prototype2.getPriority();
if(result == 0) {
// Negate integer to have the case that the order <A, B> corresponds to "A is
// greater than B" (= positive)
result = -prototype1.getName().compareTo(prototype2.getName());
}
return result;
}
});
// Reverse to get a descending order (highest prio at first / on top).
reverse(prototypesForNewMenu);
for(Prototype prototype : prototypesForNewMenu) {
EObject prototypeCopy = prototype.getPrototypeCopy();
MenuItem menuItem = createMenuItemForComposableElement(prototypeCopy, target, context,
prototype.getName());
// To prevent that underscores are swallowed up:
menuItem.setMnemonicParsing(false);
newMenu.getItems().add(menuItem);
}
if(!newMenu.getItems().isEmpty()) { if(!newMenu.getItems().isEmpty()) {
result.add(newMenu); result.add(newMenu);
} }
if(!reuseMenu.getItems().isEmpty()) {
result.add(reuseMenu);
}
return result; return result;
} }
/**
* Returns a menu item for the given element with which the element can be composed with the
* given target (in the given context).
*
* @param composableElement
* The element that should be composed.
* @param target
* The target with which the element should be composed.
* @param context
* The context of the composition.
* @param itemName
* The name of the new menu item.
* @return The newly created menu item.
*/
private static MenuItem createMenuItemForComposableElement(EObject composableElement,
EObject target, IElementCompositionContext context, String itemName) {
ICommandStackService css = ICommandStackService.getInstance();
IElementCompositorService ecs = IElementCompositorService.getInstance();
MenuItem menuItem = new MenuItem(itemName);
menuItem.setOnAction(evt -> {
css.runAsCommand(target, () -> {
ecs.compose(target, composableElement, context);
});
});
return menuItem;
}
/** /**
* Creates the menu populated with composable prototypes. * Creates the menu populated with composable prototypes.
* *
......
DiagramCoordinate.java 6b00aec99054d4cd19003a72bd4e5e774ac6a641 GREEN DiagramCoordinate.java 6b00aec99054d4cd19003a72bd4e5e774ac6a641 GREEN
DiagramLayers.java aa1f95dbae290c8b00202abe4385b01b8f36e5ab GREEN DiagramLayers.java aa1f95dbae290c8b00202abe4385b01b8f36e5ab GREEN
DiagramViewer.java 73c3c0af460ef0631f4fc8a9d674eb6ebc804ca8 YELLOW DiagramViewer.java 537358db18da8b5ba2bf56082bfd87dec3ca88d8 GREEN
DiagramViewerDefaultTags.java 6230763252409c60009ab8887b4ef582cf883229 GREEN DiagramViewerDefaultTags.java 6230763252409c60009ab8887b4ef582cf883229 GREEN
DiagramViewerFeatures.java 8909375b7116fbd7386eb7d6d8c6f0618a0673ec YELLOW DiagramViewerFeatures.java 8909375b7116fbd7386eb7d6d8c6f0618a0673ec YELLOW
DiagramViewerSelection.java e833f592543bc97077907d980a39b123fc4044e6 GREEN DiagramViewerSelection.java e833f592543bc97077907d980a39b123fc4044e6 GREEN
......
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2019, 2020 fortiss GmbH. * Copyright (c) 2023 fortiss GmbH.
* *
* This program and the accompanying materials are made available under the * This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at * terms of the Apache License, Version 2.0 which is available at
...@@ -49,6 +49,7 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IMVCBundle; ...@@ -49,6 +49,7 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IMVCBundle;
import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.MVCBundleTag; import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.MVCBundleTag;
import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisualFactory; import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisualFactory;
import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.geometry.BoundingBox; import javafx.geometry.BoundingBox;
import javafx.geometry.Bounds; import javafx.geometry.Bounds;
...@@ -248,7 +249,7 @@ public class DiagramViewer { ...@@ -248,7 +249,7 @@ public class DiagramViewer {
return viewerManager.diagramBundle; return viewerManager.diagramBundle;
} }
/** Shows the context menu when the mouse is pressed. */ /** Hides the context menu if it is active. */
/* package */ void hideContextMenu() { /* package */ void hideContextMenu() {
if(contextMenu != null && contextMenu.isShowing()) { if(contextMenu != null && contextMenu.isShowing()) {
contextMenu.hide(); contextMenu.hide();
...@@ -256,12 +257,26 @@ public class DiagramViewer { ...@@ -256,12 +257,26 @@ public class DiagramViewer {
} }
} }
/** Shows the context menu when the mouse is released. */ /** Shows the context menu. */
public void showContextMenu(Node node, DiagramCoordinate diagramLocation, IMVCBundle mvcb) { public void showContextMenu(Node node, DiagramCoordinate diagramLocation, IMVCBundle mvcb) {
List<MenuItem> items = mvcb.getController().contextMenuContributions(node, diagramLocation); List<MenuItem> items = mvcb.getController().contextMenuContributions(node, diagramLocation);
if(items == null || items.isEmpty()) { if(items == null || items.isEmpty()) {
return; return;
} }
// Extend each menu item so that when it gets clicked on, it will first hide its own context
// menu before it continues with its normal procedure (to prevent old context menus being
// still open/active behind or even in front of new windows).
for(MenuItem item : items) {
EventHandler<ActionEvent> baseEventHandler = item.getOnAction();
item.setOnAction(event -> {
hideContextMenu();
if(baseEventHandler != null) {
baseEventHandler.handle(event);
}
});
}
contextMenu = new ContextMenu(); contextMenu = new ContextMenu();
contextMenu.getItems().addAll(items); contextMenu.getItems().addAll(items);
contextMenu.setAutoHide(true); contextMenu.setAutoHide(true);
......
Subproject commit 310d1c04f28f6252d5a02dd8fde1b76ae4a4da51
AddElementContextMenu.java ab4536e73323802e46d50d0bb9f62d6becc9db39 GREEN AddElementContextMenu.java 592522843ed720c4e244793710accb0bd82bdd9d GREEN
GetUpdatedOriginsContextMenu.java cfb16bb084be5a76a7ec70c2882242543535bc87 GREEN GetUpdatedOriginsContextMenu.java a356ea9869f8279f2700222b1fd8382a29b06399 GREEN
UpdateFromLibContextMenu.java 58f56f4c2da66655a5c1bf93c370bd4f2dba5dd4 GREEN UpdateFromLibContextMenu.java 2e1e16dff85601412f0d47d6446a10fa5d3a1119 GREEN
UpdateInLibContextMenu.java cb5aeb92f8e511339bec675a3764284d977dd45d GREEN UpdateInLibContextMenu.java 69448087f3904dff7e3d7a34f508c772090cd17d GREEN
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -22,7 +22,9 @@ import static org.eclipse.jface.window.Window.OK; ...@@ -22,7 +22,9 @@ import static org.eclipse.jface.window.Window.OK;
import static org.eclipse.ui.PlatformUI.getWorkbench; import static org.eclipse.ui.PlatformUI.getWorkbench;
import static org.fortiss.tooling.ext.reuse.ui.prototypes.PrototypeProvider.DEFAULT_ROOT_REUSE_ELEMENT_NAME; import static org.fortiss.tooling.ext.reuse.ui.prototypes.PrototypeProvider.DEFAULT_ROOT_REUSE_ELEMENT_NAME;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.manageExternalReferencesOfReuseElement; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.manageExternalReferencesOfReuseElement;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfDeletedReuseElem;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryViewUtils.raiseAndUpdateReuseLibraryView; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryViewUtils.raiseAndUpdateReuseLibraryView;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.doesReuseElementExistWithContext;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getAllLocalReuseLibraries; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getAllLocalReuseLibraries;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseElementName; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseElementName;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.hasReusePossibility; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.hasReusePossibility;
...@@ -59,12 +61,17 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; ...@@ -59,12 +61,17 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
public class AddElementContextMenu implements IContextMenuContributor { public class AddElementContextMenu implements IContextMenuContributor {
/** The title of the dialog shell(s). */ /** The title of the dialog shell(s). */
private final String shellTitle = "Add Element to Reuse Library"; private static final String SHELL_TITLE = "Add Element to Reuse Library";
/** The description of the processed action. */
private static final String ACTION_DESCRIPTION =
"Adding a selected reuse element to a selected reuse library";
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public List<IContributionItem> getContributedItems(EObject selection, ContextMenuContextProvider contextProvider) { public List<IContributionItem> getContributedItems(EObject selection,
if (selection != null && canBeAdded(selection)) { ContextMenuContextProvider contextProvider) {
if(selection != null && canBeAdded(selection)) {
AddToLibAction action = new AddToLibAction(selection); AddToLibAction action = new AddToLibAction(selection);
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(action)); contributionItems.add(new ActionContributionItem(action));
...@@ -86,7 +93,7 @@ public class AddElementContextMenu implements IContextMenuContributor { ...@@ -86,7 +93,7 @@ public class AddElementContextMenu implements IContextMenuContributor {
/** Add one given element to specified {@link ReuseLibrary}. */ /** Add one given element to specified {@link ReuseLibrary}. */
protected void addElement(ReuseLibrary library, EObject elementToAdd, String saveName) { protected void addElement(ReuseLibrary library, EObject elementToAdd, String saveName) {
if (library == null || elementToAdd == null || saveName == null) { if(library == null || elementToAdd == null || saveName == null) {
return; return;
} }
...@@ -94,14 +101,15 @@ public class AddElementContextMenu implements IContextMenuContributor { ...@@ -94,14 +101,15 @@ public class AddElementContextMenu implements IContextMenuContributor {
try { try {
addElementToLibrary(newElementForLibrary, library); addElementToLibrary(newElementForLibrary, library);
} catch (Exception e) { } catch(Exception e) {
openError(getActiveWorkbenchWindow().getShell(), "Error in '" + shellTitle + "'", e.getMessage()); openError(getActiveWorkbenchWindow().getShell(), "Error in '" + SHELL_TITLE + "'",
e.getMessage());
} }
PrototypeService.getInstance().updatePrototypes(); PrototypeService.getInstance().updatePrototypes();
String currentActionType = "addToLibrary"; String currentActionType = "addToLibrary";
manageExternalReferencesOfReuseElement(elementToAdd, currentActionType, shellTitle); manageExternalReferencesOfReuseElement(elementToAdd, currentActionType, SHELL_TITLE);
} }
/** The action "add element to {@link ReuseLibrary}". */ /** The action "add element to {@link ReuseLibrary}". */
...@@ -121,7 +129,8 @@ public class AddElementContextMenu implements IContextMenuContributor { ...@@ -121,7 +129,8 @@ public class AddElementContextMenu implements IContextMenuContributor {
/** Constructor. Takes the selected element as input. */ /** Constructor. Takes the selected element as input. */
AddToLibAction(EObject element) { AddToLibAction(EObject element) {
super("Add to Reuse Library", ToolingReuseUIActivator.getImageDescriptor("icons/library_add.png")); super("Add to Reuse Library",
ToolingReuseUIActivator.getImageDescriptor("icons/library_add.png"));
selectedElement = element; selectedElement = element;
} }
...@@ -134,65 +143,80 @@ public class AddElementContextMenu implements IContextMenuContributor { ...@@ -134,65 +143,80 @@ public class AddElementContextMenu implements IContextMenuContributor {
Boolean createNewLibrary; Boolean createNewLibrary;
String creationText; String creationText;
if (libraryList != null && !libraryList.isEmpty()) { if(libraryList != null && !libraryList.isEmpty()) {
// update existing library names // Update existing library names.
for (ReuseLibrary tmpLibrary : libraryList) { for(ReuseLibrary tmpLibrary : libraryList) {
currentExistingLibraryNames.add(getReuseElementName(tmpLibrary)); currentExistingLibraryNames.add(getReuseElementName(tmpLibrary));
} }
// ask for library selection // Ask for library selection.
final Shell shell = getWorkbench().getActiveWorkbenchWindow().getShell(); final Shell shell = getWorkbench().getActiveWorkbenchWindow().getShell();
final AddElementToLibDialog librarySelectDialog = new AddElementToLibDialog(shell, shellTitle); final AddElementToLibDialog librarySelectDialog =
new AddElementToLibDialog(shell, SHELL_TITLE);
librarySelectDialog.setLibraryList(libraryList); librarySelectDialog.setLibraryList(libraryList);
librarySelectDialog.open(); librarySelectDialog.open();
if (!librarySelectDialog.goAhead()) { if(!librarySelectDialog.goAhead()) {
return; return;
} }
selectedLibrary = librarySelectDialog.getLibrary(); selectedLibrary = librarySelectDialog.getLibrary();
createNewLibrary = librarySelectDialog.createNew(); createNewLibrary = librarySelectDialog.createNew();
creationText = "A new library will be created in which the element can be added.\nEnter a name for the library:\n "; creationText =
"A new library will be created in which the element can be added.\nEnter a name for the library:\n ";
} else { } else {
createNewLibrary = true; createNewLibrary = true;
creationText = "No library exists yet to add the element. A new one will be created.\nEnter a name for the library:\n "; creationText =
"No library exists yet to add the element. A new one will be created.\nEnter a name for the library:\n ";
} }
if (createNewLibrary) { if(createNewLibrary) {
final InputDialog creationDialog = new InputDialog(Display.getCurrent().getActiveShell(), shellTitle, final InputDialog creationDialog = new InputDialog(
creationText, DEFAULT_ROOT_REUSE_ELEMENT_NAME, new NewLibNameValidator()); Display.getCurrent().getActiveShell(), SHELL_TITLE, creationText,
if (creationDialog.open() != OK) { DEFAULT_ROOT_REUSE_ELEMENT_NAME, new NewLibNameValidator());
if(creationDialog.open() != OK) {
return;
}
if(doesReuseElementExistWithContext(selectedElement)) {
ICommandStackService.getInstance().runAsCommand(selectedElement, () -> {
selectedLibrary = createAndAddReuseLibrary(creationDialog.getValue());
});
} else {
warnOfDeletedReuseElem(ACTION_DESCRIPTION, SHELL_TITLE);
return; return;
} }
ICommandStackService.getInstance().runAsCommand(selectedElement, () -> {
selectedLibrary = createAndAddReuseLibrary(creationDialog.getValue());
});
} }
if (selectedLibrary == null) { if(selectedLibrary == null) {
return; return;
} }
// update existing element names // Update existing element names.
currentExistingLibraryElementNames = new ArrayList<String>(); currentExistingLibraryElementNames = new ArrayList<String>();
EList<EObject> elementList = selectedLibrary.getReuseElementList(); EList<EObject> elementList = selectedLibrary.getReuseElementList();
for (EObject libraryElement : elementList) { for(EObject libraryElement : elementList) {
currentExistingLibraryElementNames.add(getReuseElementName(libraryElement)); currentExistingLibraryElementNames.add(getReuseElementName(libraryElement));
} }
// ask for new element name (when saving element to library) // Ask for new element name (when saving element to library).
final InputDialog addingDialog = new InputDialog(Display.getCurrent().getActiveShell(), shellTitle, final InputDialog addingDialog = new InputDialog(Display.getCurrent().getActiveShell(),
"Enter the name with which the element should be saved in the library '" SHELL_TITLE,
+ getReuseElementName(selectedLibrary) + "':\n ", "Enter the name with which the element should be saved in the library '" +
getReuseElementName(selectedLibrary) + "':\n ",
getReuseElementName(selectedElement), new AddedNameValidator()); getReuseElementName(selectedElement), new AddedNameValidator());
if (addingDialog.open() != OK) { if(addingDialog.open() != OK) {
return; return;
} }
String newName = addingDialog.getValue(); String newName = addingDialog.getValue();
// execute "adding" action // Execute "adding" action (if the element still exists).
ICommandStackService.getInstance().runAsCommand(selectedElement, () -> { if(doesReuseElementExistWithContext(selectedElement)) {
addElement(selectedLibrary, selectedElement, newName); ICommandStackService.getInstance().runAsCommand(selectedElement, () -> {
}); addElement(selectedLibrary, selectedElement, newName);
});
} else {
warnOfDeletedReuseElem(ACTION_DESCRIPTION, SHELL_TITLE);
return;
}
raiseAndUpdateReuseLibraryView(); raiseAndUpdateReuseLibraryView();
} }
...@@ -203,11 +227,11 @@ public class AddElementContextMenu implements IContextMenuContributor { ...@@ -203,11 +227,11 @@ public class AddElementContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String isValid(String newText) { public String isValid(String newText) {
if (newText.equals("")) { if(newText.equals("")) {
return "A name needs to be specified."; return "A name needs to be specified.";
} }
for (String name : currentExistingLibraryNames) { for(String name : currentExistingLibraryNames) {
if (newText.equals(name)) { if(newText.equals(name)) {
return "A library with this name already exists."; return "A library with this name already exists.";
} }
} }
...@@ -221,11 +245,11 @@ public class AddElementContextMenu implements IContextMenuContributor { ...@@ -221,11 +245,11 @@ public class AddElementContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String isValid(String newText) { public String isValid(String newText) {
if (newText.equals("")) { if(newText.equals("")) {
return "A name needs to be specified."; return "A name needs to be specified.";
} }
for (String name : currentExistingLibraryElementNames) { for(String name : currentExistingLibraryElementNames) {
if (newText.equals(name)) { if(newText.equals(name)) {
return "This name already exists. Please use another."; return "This name already exists. Please use another.";
} }
} }
......
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2022 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -18,6 +18,8 @@ package org.fortiss.tooling.ext.reuse.ui.commands; ...@@ -18,6 +18,8 @@ package org.fortiss.tooling.ext.reuse.ui.commands;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.conqat.ide.commons.ui.dialog.MessageUtils.showInfo; import static org.conqat.ide.commons.ui.dialog.MessageUtils.showInfo;
import static org.fortiss.tooling.ext.reuse.ui.commands.UpdateFromLibContextMenu.UPDATE_FROM_CONTEXT_MENU_STRING; import static org.fortiss.tooling.ext.reuse.ui.commands.UpdateFromLibContextMenu.UPDATE_FROM_CONTEXT_MENU_STRING;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfDeletedReuseElem;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.doesReuseElementExistWithContext;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getAllUpdatedOrigins; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getAllUpdatedOrigins;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getFirstSourceLibraryOfElement; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getFirstSourceLibraryOfElement;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLibraryIDName; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLibraryIDName;
...@@ -48,15 +50,20 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider; ...@@ -48,15 +50,20 @@ import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
public class GetUpdatedOriginsContextMenu implements IContextMenuContributor { public class GetUpdatedOriginsContextMenu implements IContextMenuContributor {
/** The title of the dialog shell(s). */ /** The title of the dialog shell(s). */
private final String shellTitle = "Information about updated reuse origins"; private static final String SHELL_TITLE = "Information about updated reuse origins";
/** The description of the processed action. */
private static final String ACTION_DESCRIPTION =
"Informing the user about updated reuse origins";
/** The string of the context menu entry. */ /** The string of the context menu entry. */
public static final String updatedOrigincontextMenuString = "Get reuse update information"; public static final String updatedOrigincontextMenuString = "Get reuse update information";
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public List<IContributionItem> getContributedItems(EObject selection, ContextMenuContextProvider contextProvider) { public List<IContributionItem> getContributedItems(EObject selection,
if (selection != null && canBeAdded(selection)) { ContextMenuContextProvider contextProvider) {
if(selection != null && canBeAdded(selection)) {
GetUpdateInfoAction action = new GetUpdateInfoAction(selection); GetUpdateInfoAction action = new GetUpdateInfoAction(selection);
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(action)); contributionItems.add(new ActionContributionItem(action));
...@@ -84,7 +91,7 @@ public class GetUpdatedOriginsContextMenu implements IContextMenuContributor { ...@@ -84,7 +91,7 @@ public class GetUpdatedOriginsContextMenu implements IContextMenuContributor {
* element. * element.
*/ */
protected void displayOriginUpdateInfo(EObject reuseElement) { protected void displayOriginUpdateInfo(EObject reuseElement) {
if (reuseElement == null) { if(reuseElement == null) {
return; return;
} }
...@@ -94,26 +101,29 @@ public class GetUpdatedOriginsContextMenu implements IContextMenuContributor { ...@@ -94,26 +101,29 @@ public class GetUpdatedOriginsContextMenu implements IContextMenuContributor {
// It could also be possible to provide directly update options within this // It could also be possible to provide directly update options within this
// info/dialog box. // info/dialog box.
String infoMessage; String infoMessage;
if (updatedReuseOrigins.isEmpty()) { if(updatedReuseOrigins.isEmpty()) {
infoMessage = "None of the found reuse origins was updated since the selected reuse element was reused or updated (based of these origins)." infoMessage =
+ "\n\nTherefore, it is not needed to get updates from any of them except you want to get the original version (e.g., if you have manipulated the selected reuse element in the meantime and wants to reset it)." "None of the found reuse origins was updated since the selected reuse element was reused or updated (based of these origins)." +
+ "\n\nKeep in mind: Updated reuse origins cannot be found if your local reuse libraries are not up to date as well!"; "\n\nTherefore, it is not needed to get updates from any of them except you want to get the original version (e.g., if you have manipulated the selected reuse element in the meantime and wants to reset it)." +
"\n\nKeep in mind: Updated reuse origins cannot be found if your local reuse libraries are not up to date as well!";
} else { } else {
infoMessage = "The following reuse origins of the selected reuse element were updated since the selected reuse element was reused or updated (based of these origins):\n"; infoMessage =
for (EObject updatedReuseOrigin : updatedReuseOrigins) { "The following reuse origins of the selected reuse element were updated since the selected reuse element was reused or updated (based of these origins):\n";
for(EObject updatedReuseOrigin : updatedReuseOrigins) {
String reuseElementName = getReuseElementName(updatedReuseOrigin); String reuseElementName = getReuseElementName(updatedReuseOrigin);
ReuseLibrary library = getFirstSourceLibraryOfElement(updatedReuseOrigin); ReuseLibrary library = getFirstSourceLibraryOfElement(updatedReuseOrigin);
String libraryName = getLibraryIDName(library); String libraryName = getLibraryIDName(library);
boolean stringIsForDisplay = true; boolean stringIsForDisplay = true;
String lastUpdate = getReuseElementLastUpdateString(updatedReuseOrigin, stringIsForDisplay); String lastUpdate =
getReuseElementLastUpdateString(updatedReuseOrigin, stringIsForDisplay);
infoMessage += "\nName: '" + reuseElementName + "'\n"; infoMessage += "\nName: '" + reuseElementName + "'\n";
infoMessage += "Within library: '" + libraryName + "'\n"; infoMessage += "Within library: '" + libraryName + "'\n";
infoMessage += "Last updated: " + lastUpdate + "\n"; infoMessage += "Last updated: " + lastUpdate + "\n";
} }
infoMessage += "\nIf you want to get one of these updates, please use the '" infoMessage += "\nIf you want to get one of these updates, please use the '" +
+ UPDATE_FROM_CONTEXT_MENU_STRING + "' context menu entry."; UPDATE_FROM_CONTEXT_MENU_STRING + "' context menu entry.";
} }
showInfo(shellTitle, infoMessage); showInfo(SHELL_TITLE, infoMessage);
} }
/** The action "get info about reuse origin updates". */ /** The action "get info about reuse origin updates". */
...@@ -132,9 +142,14 @@ public class GetUpdatedOriginsContextMenu implements IContextMenuContributor { ...@@ -132,9 +142,14 @@ public class GetUpdatedOriginsContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void run() { public void run() {
ICommandStackService.getInstance().runAsCommand(selectedElement, () -> { if(doesReuseElementExistWithContext(selectedElement)) {
displayOriginUpdateInfo(selectedElement); ICommandStackService.getInstance().runAsCommand(selectedElement, () -> {
}); displayOriginUpdateInfo(selectedElement);
});
} else {
warnOfDeletedReuseElem(ACTION_DESCRIPTION, SHELL_TITLE);
return;
}
} }
} }
} }
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -24,7 +24,9 @@ import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.checkFo ...@@ -24,7 +24,9 @@ import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.checkFo
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.isKeepingAdditionalReferencesRequested; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.isKeepingAdditionalReferencesRequested;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.manageExternalReferencesOfReuseElement; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.manageExternalReferencesOfReuseElement;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.selectCorrectReuseSpec; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.selectCorrectReuseSpec;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfDeletedReuseElem;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfMissingLib; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfMissingLib;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.doesReuseElementExistWithContext;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLibraryIDName; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLibraryIDName;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLocalReuseLibraryByID; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLocalReuseLibraryByID;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getNumberOfContainedReuseSpecs; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getNumberOfContainedReuseSpecs;
...@@ -65,13 +67,18 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -65,13 +67,18 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
/** The title of the dialog shell(s). */ /** The title of the dialog shell(s). */
private static final String SHELL_TITLE = "Update Element From Reuse Library"; private static final String SHELL_TITLE = "Update Element From Reuse Library";
/** The description of the processed action. */
private static final String ACTION_DESCRIPTION =
"Updating the selected reuse element from a selected reuse library";
/** The string of the context menu entry. */ /** The string of the context menu entry. */
public static final String UPDATE_FROM_CONTEXT_MENU_STRING = "Update from Reuse Library"; public static final String UPDATE_FROM_CONTEXT_MENU_STRING = "Update from Reuse Library";
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public List<IContributionItem> getContributedItems(EObject selection, ContextMenuContextProvider contextProvider) { public List<IContributionItem> getContributedItems(EObject selection,
if (selection != null && canBeUpdated(selection)) { ContextMenuContextProvider contextProvider) {
if(selection != null && canBeUpdated(selection)) {
UpdateFromLibAction action = new UpdateFromLibAction(selection); UpdateFromLibAction action = new UpdateFromLibAction(selection);
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(action)); contributionItems.add(new ActionContributionItem(action));
...@@ -101,22 +108,24 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -101,22 +108,24 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
*/ */
protected void updateElementFromLibrary(EObject elementToBeUpdated, ReuseLibrary library, protected void updateElementFromLibrary(EObject elementToBeUpdated, ReuseLibrary library,
ReuseElementSpec referencingSpec, String newName, boolean keepAdditionalReferences) { ReuseElementSpec referencingSpec, String newName, boolean keepAdditionalReferences) {
if (library == null || elementToBeUpdated == null || referencingSpec == null || newName == null) { if(library == null || elementToBeUpdated == null || referencingSpec == null ||
newName == null) {
return; return;
} }
// find original element inside the library // Find original element inside the library.
EObject originalLibraryElement = checkForElementInLibrary(library, referencingSpec, SHELL_TITLE); EObject originalLibraryElement =
if (originalLibraryElement == null) { checkForElementInLibrary(library, referencingSpec, SHELL_TITLE);
if(originalLibraryElement == null) {
return; return;
} }
EObject updatedElement = replaceElementInProject(elementToBeUpdated, originalLibraryElement, newName, EObject updatedElement = replaceElementInProject(elementToBeUpdated, originalLibraryElement,
keepAdditionalReferences); newName, keepAdditionalReferences);
if (updatedElement == null) { if(updatedElement == null) {
String infoTitle = SHELL_TITLE + " - Replacement Failed"; String infoTitle = SHELL_TITLE + " - Replacement Failed";
String infoMessage = "The replacement of '" + getReuseElementName(elementToBeUpdated) + "' with '" String infoMessage = "The replacement of '" + getReuseElementName(elementToBeUpdated) +
+ getReuseElementName(originalLibraryElement) + "' has failed."; "' with '" + getReuseElementName(originalLibraryElement) + "' has failed.";
showInfo(infoTitle, infoMessage); showInfo(infoTitle, infoMessage);
return; return;
} }
...@@ -124,7 +133,8 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -124,7 +133,8 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
fixIDs(updatedElement); fixIDs(updatedElement);
String currentActionType = "updateFromLibrary"; String currentActionType = "updateFromLibrary";
manageExternalReferencesOfReuseElement(originalLibraryElement, currentActionType, SHELL_TITLE); manageExternalReferencesOfReuseElement(originalLibraryElement, currentActionType,
SHELL_TITLE);
} }
/** The action "update element from {@link ReuseLibrary}". */ /** The action "update element from {@link ReuseLibrary}". */
...@@ -143,40 +153,43 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -143,40 +153,43 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void run() { public void run() {
ReuseElementSpec correctLibrarySpec = selectCorrectReuseSpec(selectedElement, SHELL_TITLE); ReuseElementSpec correctLibrarySpec =
if (correctLibrarySpec == null) { selectCorrectReuseSpec(selectedElement, SHELL_TITLE);
if(correctLibrarySpec == null) {
return; return;
} }
ReuseLibrary correctLibrary = getLocalReuseLibraryByID(correctLibrarySpec.getSourceLibUUID()); ReuseLibrary correctLibrary =
getLocalReuseLibraryByID(correctLibrarySpec.getSourceLibUUID());
if (correctLibrary == null) { if(correctLibrary == null) {
warnOfMissingLib(correctLibrarySpec, SHELL_TITLE); warnOfMissingLib(correctLibrarySpec, SHELL_TITLE);
return; return;
} }
String currentNameInProject = getReuseElementName(selectedElement); String currentNameInProject = getReuseElementName(selectedElement);
String currentProjectName = "not found"; String currentProjectName = "not found";
EList<INamedCommentedElement> parentList = getParentsWithType(selectedElement, EList<INamedCommentedElement> parentList =
INamedCommentedElement.class); getParentsWithType(selectedElement, INamedCommentedElement.class);
if (parentList != null && !parentList.isEmpty()) { if(parentList != null && !parentList.isEmpty()) {
// safe due to check above and last element is the highest parent aka root // Safe due to check above and last element is the highest parent aka root.
INamedCommentedElement root = parentList.get(parentList.size() - 1); INamedCommentedElement root = parentList.get(parentList.size() - 1);
currentProjectName = root.getName(); currentProjectName = root.getName();
} }
// find original element inside the library // Find original element inside the library.
EObject originalLibraryElement = checkForElementInLibrary(correctLibrary, correctLibrarySpec, SHELL_TITLE); EObject originalLibraryElement =
if (originalLibraryElement == null) { checkForElementInLibrary(correctLibrary, correctLibrarySpec, SHELL_TITLE);
if(originalLibraryElement == null) {
return; return;
} }
// in case of multiple library references within the selected element, ask if // In case of multiple library references within the selected element, ask if
// they should be kept or if all should be overridden/replaced by the library // they should be kept or if all should be overridden/replaced by the library
// reference of the current update // reference of the current update.
boolean keepAdditionalReferences = isKeepingAdditionalReferencesRequested(selectedElement, boolean keepAdditionalReferences = isKeepingAdditionalReferencesRequested(
correctLibrarySpec, SHELL_TITLE); selectedElement, correctLibrarySpec, SHELL_TITLE);
// confirm the update // Confirm the update.
String currentNameInLibrary = getReuseElementName(originalLibraryElement); String currentNameInLibrary = getReuseElementName(originalLibraryElement);
List<String> textLines = new ArrayList<String>(); List<String> textLines = new ArrayList<String>();
textLines.add("Confirm the following update (from source to target):"); textLines.add("Confirm the following update (from source to target):");
...@@ -186,8 +199,8 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -186,8 +199,8 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
textLines.add("\n- Update target: element in current project"); textLines.add("\n- Update target: element in current project");
textLines.add(" > element name: " + currentNameInProject); textLines.add(" > element name: " + currentNameInProject);
textLines.add(" > in project: " + currentProjectName); textLines.add(" > in project: " + currentProjectName);
if (getNumberOfContainedReuseSpecs(selectedElement) > 1) { if(getNumberOfContainedReuseSpecs(selectedElement) > 1) {
if (keepAdditionalReferences) { if(keepAdditionalReferences) {
textLines.add( textLines.add(
"\nBesides the current update reference, all (old) additional library references will be kept within the element."); "\nBesides the current update reference, all (old) additional library references will be kept within the element.");
} else { } else {
...@@ -197,25 +210,31 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -197,25 +210,31 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
} }
boolean confirmed = confirm(SHELL_TITLE, join("\n", textLines)); boolean confirmed = confirm(SHELL_TITLE, join("\n", textLines));
if (!confirmed) { if(!confirmed) {
return; return;
} }
// ask for element name (when updating element in project) // Ask for element name (when updating element in project).
final InputDialog updateDialog = new InputDialog(Display.getCurrent().getActiveShell(), SHELL_TITLE, final InputDialog updateDialog = new InputDialog(Display.getCurrent().getActiveShell(),
"Enter the name with which the element should be updated in the project:\n(Current name in project: " SHELL_TITLE,
+ currentNameInProject + ")\n ", "Enter the name with which the element should be updated in the project:\n(Current name in project: " +
currentNameInProject + ")\n ",
currentNameInProject, new UpdatedNameValidator()); currentNameInProject, new UpdatedNameValidator());
if (updateDialog.open() != OK) { if(updateDialog.open() != OK) {
return; return;
} }
String updateName = updateDialog.getValue(); String updateName = updateDialog.getValue();
// execute "updating" action // Execute "updating" action (if the selected element still exists).
ICommandStackService.getInstance().runAsCommand(selectedElement, () -> { if(doesReuseElementExistWithContext(selectedElement)) {
updateElementFromLibrary(selectedElement, correctLibrary, correctLibrarySpec, updateName, ICommandStackService.getInstance().runAsCommand(selectedElement, () -> {
keepAdditionalReferences); updateElementFromLibrary(selectedElement, correctLibrary, correctLibrarySpec,
}); updateName, keepAdditionalReferences);
});
} else {
warnOfDeletedReuseElem(ACTION_DESCRIPTION, SHELL_TITLE);
return;
}
} }
/** Validator for the name of the updated element. */ /** Validator for the name of the updated element. */
...@@ -224,12 +243,11 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor { ...@@ -224,12 +243,11 @@ public class UpdateFromLibContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String isValid(String newText) { public String isValid(String newText) {
if (newText.equals("")) { if(newText.equals("")) {
return "A name needs to be specified."; return "A name needs to be specified.";
} }
return null; return null;
} }
} }
} }
} }
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -25,8 +25,10 @@ import static org.fortiss.tooling.ext.reuse.storage.ReuseLibraryStorageManager.s ...@@ -25,8 +25,10 @@ import static org.fortiss.tooling.ext.reuse.storage.ReuseLibraryStorageManager.s
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.checkForElementInLibrary; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.checkForElementInLibrary;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.manageExternalReferencesOfReuseElement; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.manageExternalReferencesOfReuseElement;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.selectCorrectReuseSpec; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.selectCorrectReuseSpec;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfDeletedReuseElem;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfMissingLib; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryUIUtils.warnOfMissingLib;
import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryViewUtils.raiseAndUpdateReuseLibraryView; import static org.fortiss.tooling.ext.reuse.ui.utils.ReuseLibraryViewUtils.raiseAndUpdateReuseLibraryView;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.doesReuseElementExistWithContext;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLibraryIDName; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLibraryIDName;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLocalReuseLibraryByID; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getLocalReuseLibraryByID;
import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseElementName; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseElementName;
...@@ -66,13 +68,18 @@ public class UpdateInLibContextMenu implements IContextMenuContributor { ...@@ -66,13 +68,18 @@ public class UpdateInLibContextMenu implements IContextMenuContributor {
/** The title of the dialog shell(s). */ /** The title of the dialog shell(s). */
private static final String SHELL_TITLE = "Update Element In Reuse Library"; private static final String SHELL_TITLE = "Update Element In Reuse Library";
/** The description of the processed action. */
private static final String ACTION_DESCRIPTION =
"Updating the selected reuse element inside the selected reuse library";
/** The string of the context menu entry. */ /** The string of the context menu entry. */
public static final String UPDATE_IN_CONTEXT_MENU_STRING = "Update in Reuse Library"; public static final String UPDATE_IN_CONTEXT_MENU_STRING = "Update in Reuse Library";
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public List<IContributionItem> getContributedItems(EObject selection, ContextMenuContextProvider contextProvider) { public List<IContributionItem> getContributedItems(EObject selection,
if (selection != null && canBeUpdated(selection)) { ContextMenuContextProvider contextProvider) {
if(selection != null && canBeUpdated(selection)) {
UpdateInLibAction action = new UpdateInLibAction(selection); UpdateInLibAction action = new UpdateInLibAction(selection);
List<IContributionItem> contributionItems = new ArrayList<IContributionItem>(); List<IContributionItem> contributionItems = new ArrayList<IContributionItem>();
contributionItems.add(new ActionContributionItem(action)); contributionItems.add(new ActionContributionItem(action));
...@@ -101,22 +108,24 @@ public class UpdateInLibContextMenu implements IContextMenuContributor { ...@@ -101,22 +108,24 @@ public class UpdateInLibContextMenu implements IContextMenuContributor {
* {@link ReuseElementSpec} is the one that connects reuse element and * {@link ReuseElementSpec} is the one that connects reuse element and
* {@link ReuseLibrary}. * {@link ReuseLibrary}.
*/ */
protected void updateElemInLib(EObject newElement, ReuseLibrary library, ReuseElementSpec referencingSpec, protected void updateElemInLib(EObject newElement, ReuseLibrary library,
String newName) { ReuseElementSpec referencingSpec, String newName) {
if (library == null || newElement == null || referencingSpec == null || newName == null) { if(library == null || newElement == null || referencingSpec == null || newName == null) {
return; return;
} }
EObject originalLibraryElement = checkForElementInLibrary(library, referencingSpec, SHELL_TITLE); EObject originalLibraryElement =
if (originalLibraryElement == null) { checkForElementInLibrary(library, referencingSpec, SHELL_TITLE);
if(originalLibraryElement == null) {
return; return;
} }
replaceElementInLibrary(originalLibraryElement, newElement, referencingSpec, newName); replaceElementInLibrary(originalLibraryElement, newElement, referencingSpec, newName);
try { try {
saveReuseLibrary(library); saveReuseLibrary(library);
} catch (Exception e) { } catch(Exception e) {
openError(getActiveWorkbenchWindow().getShell(), "Error in '" + SHELL_TITLE + "'", e.getMessage()); openError(getActiveWorkbenchWindow().getShell(), "Error in '" + SHELL_TITLE + "'",
e.getMessage());
} }
PrototypeService.getInstance().updatePrototypes(); PrototypeService.getInstance().updatePrototypes();
...@@ -144,33 +153,36 @@ public class UpdateInLibContextMenu implements IContextMenuContributor { ...@@ -144,33 +153,36 @@ public class UpdateInLibContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void run() { public void run() {
ReuseElementSpec correctLibrarySpec = selectCorrectReuseSpec(selectedElement, SHELL_TITLE); ReuseElementSpec correctLibrarySpec =
if (correctLibrarySpec == null) { selectCorrectReuseSpec(selectedElement, SHELL_TITLE);
if(correctLibrarySpec == null) {
return; return;
} }
ReuseLibrary correctLibrary = getLocalReuseLibraryByID(correctLibrarySpec.getSourceLibUUID()); ReuseLibrary correctLibrary =
getLocalReuseLibraryByID(correctLibrarySpec.getSourceLibUUID());
if (correctLibrary == null) { if(correctLibrary == null) {
warnOfMissingLib(correctLibrarySpec, SHELL_TITLE); warnOfMissingLib(correctLibrarySpec, SHELL_TITLE);
return; return;
} }
// find original element inside the library // Find original element inside the library.
EObject originalLibraryElement = checkForElementInLibrary(correctLibrary, correctLibrarySpec, SHELL_TITLE); EObject originalLibraryElement =
if (originalLibraryElement == null) { checkForElementInLibrary(correctLibrary, correctLibrarySpec, SHELL_TITLE);
if(originalLibraryElement == null) {
return; return;
} }
String currentNameInLibrary = getReuseElementName(originalLibraryElement); String currentNameInLibrary = getReuseElementName(originalLibraryElement);
String currentProjectName = "not found"; String currentProjectName = "not found";
EList<INamedCommentedElement> parentList = getParentsWithType(selectedElement, EList<INamedCommentedElement> parentList =
INamedCommentedElement.class); getParentsWithType(selectedElement, INamedCommentedElement.class);
if (parentList != null && !parentList.isEmpty()) { if(parentList != null && !parentList.isEmpty()) {
// safe due to check above and last element is the highest parent aka root // Safe due to check above and last element is the highest parent aka root.
INamedCommentedElement root = parentList.get(parentList.size() - 1); INamedCommentedElement root = parentList.get(parentList.size() - 1);
currentProjectName = root.getName(); currentProjectName = root.getName();
} }
// confirm the update // Confirm the update.
List<String> textLines = new ArrayList<String>(); List<String> textLines = new ArrayList<String>();
textLines.add("Confirm the following update (from source to target):"); textLines.add("Confirm the following update (from source to target):");
textLines.add("\n- Update source: element in current project"); textLines.add("\n- Update source: element in current project");
...@@ -181,35 +193,42 @@ public class UpdateInLibContextMenu implements IContextMenuContributor { ...@@ -181,35 +193,42 @@ public class UpdateInLibContextMenu implements IContextMenuContributor {
textLines.add(" > in library: " + getLibraryIDName(correctLibrary)); textLines.add(" > in library: " + getLibraryIDName(correctLibrary));
boolean confirmed = confirm(SHELL_TITLE, join("\n", textLines)); boolean confirmed = confirm(SHELL_TITLE, join("\n", textLines));
if (!confirmed) { if(!confirmed) {
return; return;
} }
// update existing element names // Update existing element names.
currentExistingLibraryElementNames = new ArrayList<String>(); currentExistingLibraryElementNames = new ArrayList<String>();
EList<EObject> elementList = correctLibrary.getReuseElementList(); EList<EObject> elementList = correctLibrary.getReuseElementList();
for (EObject libraryElement : elementList) { for(EObject libraryElement : elementList) {
String name = getReuseElementName(libraryElement); String name = getReuseElementName(libraryElement);
if (!name.equals(currentNameInLibrary)) { if(!name.equals(currentNameInLibrary)) {
currentExistingLibraryElementNames.add(name); currentExistingLibraryElementNames.add(name);
} }
} }
// ask for element name (when updating element in library) // Ask for element name (when updating element in library).
final InputDialog updateDialog = new InputDialog(Display.getCurrent().getActiveShell(), SHELL_TITLE, final InputDialog updateDialog = new InputDialog(Display.getCurrent().getActiveShell(),
"Enter the name with which the element should be updated in the library '" SHELL_TITLE,
+ getReuseElementName(correctLibrary) + "':\n(Current name in library: " "Enter the name with which the element should be updated in the library '" +
+ currentNameInLibrary + ")\n ", getReuseElementName(correctLibrary) + "':\n(Current name in library: " +
currentNameInLibrary + ")\n ",
currentNameInLibrary, new UpdatedNameValidator()); currentNameInLibrary, new UpdatedNameValidator());
if (updateDialog.open() != OK) { if(updateDialog.open() != OK) {
return; return;
} }
String updateName = updateDialog.getValue(); String updateName = updateDialog.getValue();
// execute "updating" action // Execute "updating" action (if the selected element still exists).
ICommandStackService.getInstance().runAsCommand(selectedElement, () -> { if(doesReuseElementExistWithContext(selectedElement)) {
updateElemInLib(selectedElement, correctLibrary, correctLibrarySpec, updateName); ICommandStackService.getInstance().runAsCommand(selectedElement, () -> {
}); updateElemInLib(selectedElement, correctLibrary, correctLibrarySpec,
updateName);
});
} else {
warnOfDeletedReuseElem(ACTION_DESCRIPTION, SHELL_TITLE);
return;
}
raiseAndUpdateReuseLibraryView(); raiseAndUpdateReuseLibraryView();
} }
...@@ -220,17 +239,16 @@ public class UpdateInLibContextMenu implements IContextMenuContributor { ...@@ -220,17 +239,16 @@ public class UpdateInLibContextMenu implements IContextMenuContributor {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public String isValid(String newText) { public String isValid(String newText) {
if (newText.equals("")) { if(newText.equals("")) {
return "A name needs to be specified."; return "A name needs to be specified.";
} }
for (String name : currentExistingLibraryElementNames) { for(String name : currentExistingLibraryElementNames) {
if (newText.equals(name)) { if(newText.equals(name)) {
return "This name already exists. Please use another."; return "This name already exists. Please use another.";
} }
} }
return null; return null;
} }
} }
} }
} }
AddElementToLibDialog.java 357ddbf24d5e1776ae248c611ab6b40861cc548b GREEN AddElementToLibDialog.java ed34eb86c8f4d625e215f6d7f699d49278ea7bc8 GREEN
SelectLibDialog.java dce5cabd034a8a517d782fae05bda7b183b11bc6 GREEN SelectLibDialog.java c14b3c231a90ec576cdbf876caa1278323b0cc28 GREEN
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
......
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
......
ReuseLibraryUIUtils.java fed62784975bf8e6fc1625505636e247dfb6c86e GREEN ReuseLibraryUIUtils.java 15322522b537abb35ea44ec8089b4bd2f397f3b3 GREEN
ReuseLibraryViewUtils.java 34a852dc692ec56cb3e9fd8dcea99d64f31503b3 GREEN ReuseLibraryViewUtils.java 34a852dc692ec56cb3e9fd8dcea99d64f31503b3 GREEN
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -65,31 +65,33 @@ public class ReuseLibraryUIUtils { ...@@ -65,31 +65,33 @@ public class ReuseLibraryUIUtils {
* {@link ReuseElementSpec}s of the given element. Returns null if no * {@link ReuseElementSpec}s of the given element. Returns null if no
* {@link ReuseElementSpec} could be selected. * {@link ReuseElementSpec} could be selected.
* *
* @param element The target reuse element (source of the * @param element
* {@link ReuseElementSpec}) * The target reuse element (source of the
* @param dialogTitle The title for the dialog with the user * {@link ReuseElementSpec})
* @param dialogTitle
* The title for the dialog with the user
* @return The {@link ReuseElementSpec} selected by the user * @return The {@link ReuseElementSpec} selected by the user
*/ */
public static ReuseElementSpec selectCorrectReuseSpec(EObject element, String dialogTitle) { public static ReuseElementSpec selectCorrectReuseSpec(EObject element, String dialogTitle) {
if (element instanceof IModelElement) { if(element instanceof IModelElement) {
List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); List<ReuseElementSpec> specs = getAllReuseSpecs(element);
if (specs.size() == 1) { if(specs.size() == 1) {
// get(0) is safe due to size check // get(0) is safe due to size check.
return specs.get(0); return specs.get(0);
} else if (specs.size() > 1) { } else if(specs.size() > 1) {
// ask for selection // Ask for selection.
List<String> referencedLibrarySelection = new ArrayList<String>(); List<String> referencedLibrarySelection = new ArrayList<String>();
for (ReuseElementSpec spec : specs) { for(ReuseElementSpec spec : specs) {
referencedLibrarySelection referencedLibrarySelection.add(getLibraryIDNameFormat(spec.getSourceLibUUID(),
.add(getLibraryIDNameFormat(spec.getSourceLibUUID(), spec.getSourceLibName()) spec.getSourceLibName()) + " with reference to element '" +
+ " with reference to element '" + spec.getElementName() + "'"); spec.getElementName() + "'");
} }
final Shell shell = getActiveWorkbenchWindow().getShell(); final Shell shell = getActiveWorkbenchWindow().getShell();
final SelectLibDialog selectLibraryDialog = new SelectLibDialog(shell, dialogTitle); final SelectLibDialog selectLibraryDialog = new SelectLibDialog(shell, dialogTitle);
selectLibraryDialog.setLibraryNameList(referencedLibrarySelection); selectLibraryDialog.setLibraryNameList(referencedLibrarySelection);
selectLibraryDialog.open(); selectLibraryDialog.open();
if (selectLibraryDialog.goAhead()) { if(selectLibraryDialog.goAhead()) {
return specs.get(selectLibraryDialog.getSelectionIndex()); return specs.get(selectLibraryDialog.getSelectionIndex());
} }
} }
...@@ -103,38 +105,45 @@ public class ReuseLibraryUIUtils { ...@@ -103,38 +105,45 @@ public class ReuseLibraryUIUtils {
* given main {@link ReuseElementSpec} or wants to override/delete all of them. * given main {@link ReuseElementSpec} or wants to override/delete all of them.
* If no additional {@link ReuseElementSpec} was found, it will return true. * If no additional {@link ReuseElementSpec} was found, it will return true.
* *
* @param element The target reuse element (containing the library * @param element
* references) * The target reuse element (containing the library
* @param mainReference The main library reference to which the others are * references)
* additional * @param mainReference
* @param dialogTitle The title for the dialog with the user * The main library reference to which the others are
* additional
* @param dialogTitle
* The title for the dialog with the user
* @return True if (possible) additional library references should be kept or * @return True if (possible) additional library references should be kept or
* false if they should be overridden * false if they should be overridden
*/ */
public static boolean isKeepingAdditionalReferencesRequested(EObject element, ReuseElementSpec mainReference, public static boolean isKeepingAdditionalReferencesRequested(EObject element,
String dialogTitle) { ReuseElementSpec mainReference, String dialogTitle) {
if (element instanceof IModelElement) { if(element instanceof IModelElement) {
List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); List<ReuseElementSpec> specs = getAllReuseSpecs(element);
// only if we have any additional references/reuse specifications, we need to // Only if we have any additional references/reuse specifications, we need to
// ask (otherwise keeping is false, because "not existing refs/specs" do not be // ask (otherwise keeping is false, because "not existing refs/specs" do not be
// need to kept) // need to kept).
if (specs.size() > 1) { if(specs.size() > 1) {
List<String> additionalLibraryReferences = new ArrayList<String>(); List<String> additionalLibraryReferences = new ArrayList<String>();
for (ReuseElementSpec spec : specs) { for(ReuseElementSpec spec : specs) {
if (spec != mainReference) { if(spec != mainReference) {
additionalLibraryReferences.add( additionalLibraryReferences.add("- Library '" +
"- Library '" + getLibraryIDNameFormat(spec.getSourceLibUUID(), spec.getSourceLibName()) getLibraryIDNameFormat(spec.getSourceLibUUID(),
+ "' with '" + spec.getElementName() + "' as element name in the library"); spec.getSourceLibName()) +
"' with '" + spec.getElementName() +
"' as element name in the library");
} }
} }
List<String> textLines = new ArrayList<String>(); List<String> textLines = new ArrayList<String>();
textLines.add("The following additional library references were found in the selected element:"); textLines.add(
"The following additional library references were found in the selected element:");
textLines.addAll(additionalLibraryReferences); textLines.addAll(additionalLibraryReferences);
textLines.add("\nDo you want to keep them after the update?"); textLines.add("\nDo you want to keep them after the update?");
textLines.add( textLines.add(
"- Yes: All additional (old) references will be kept together with the one of the current update."); "- Yes: All additional (old) references will be kept together with the one of the current update.");
textLines.add("- No: Then, only the library reference of the current update will further exist."); textLines.add(
"- No: Then, only the library reference of the current update will further exist.");
return askQuestion(dialogTitle, join("\n", textLines)); return askQuestion(dialogTitle, join("\n", textLines));
} }
} }
...@@ -146,17 +155,20 @@ public class ReuseLibraryUIUtils { ...@@ -146,17 +155,20 @@ public class ReuseLibraryUIUtils {
* by the given {@link ReuseElementSpec}. Also, displays warning (with * by the given {@link ReuseElementSpec}. Also, displays warning (with
* dialogTitle as header) if it could not be found, and then returns null. * dialogTitle as header) if it could not be found, and then returns null.
* *
* @param library The target/source reuse library * @param library
* @param referencingSpec The reuse specification that reference the requested * The target/source reuse library
* reuse element * @param referencingSpec
* @param dialogTitle The title for the dialog * The reuse specification that reference the requested
* reuse element
* @param dialogTitle
* The title for the dialog
* @return The requested reuse element if it could be found, otherwise null * @return The requested reuse element if it could be found, otherwise null
*/ */
public static EObject checkForElementInLibrary(ReuseLibrary library, ReuseElementSpec referencingSpec, public static EObject checkForElementInLibrary(ReuseLibrary library,
String dialogTitle) { ReuseElementSpec referencingSpec, String dialogTitle) {
String targetUuid = referencingSpec.getElementUUID(); String targetUuid = referencingSpec.getElementUUID();
EObject originalElementInLibrary = getElementInsideLibrary(library, targetUuid); EObject originalElementInLibrary = getElementInsideLibrary(library, targetUuid);
if (originalElementInLibrary == null) { if(originalElementInLibrary == null) {
warnOfMissingReuseElem(referencingSpec, dialogTitle); warnOfMissingReuseElem(referencingSpec, dialogTitle);
} }
return originalElementInLibrary; return originalElementInLibrary;
...@@ -166,16 +178,19 @@ public class ReuseLibraryUIUtils { ...@@ -166,16 +178,19 @@ public class ReuseLibraryUIUtils {
* Displays a warning message to the user about a missing reuse element (with * Displays a warning message to the user about a missing reuse element (with
* extracted properties from the given {@link ReuseElementSpec} and title). * extracted properties from the given {@link ReuseElementSpec} and title).
* *
* @param referencingSpec The reuse specification that has the information about * @param referencingSpec
* the missing reuse element * The reuse specification that has the information about
* @param dialogTitle The title for the dialog * the missing reuse element
* @param dialogTitle
* The title for the dialog
*/ */
public static void warnOfMissingReuseElem(ReuseElementSpec referencingSpec, String dialogTitle) { public static void warnOfMissingReuseElem(ReuseElementSpec referencingSpec,
String dialogTitle) {
List<String> textLines = new ArrayList<String>(); List<String> textLines = new ArrayList<String>();
textLines.add("The referenced element does not exist in the referenced library."); textLines.add("The referenced element does not exist in the referenced library.");
textLines.add("\nSearched for element UUID: " + referencingSpec.getElementUUID()); textLines.add("\nSearched for element UUID: " + referencingSpec.getElementUUID());
textLines.add("in library: " textLines.add("in library: " + getLibraryIDNameFormat(referencingSpec.getSourceLibUUID(),
+ getLibraryIDNameFormat(referencingSpec.getSourceLibUUID(), referencingSpec.getSourceLibName())); referencingSpec.getSourceLibName()));
showWarning(dialogTitle + " - Missing Element", join("\n", textLines)); showWarning(dialogTitle + " - Missing Element", join("\n", textLines));
} }
...@@ -184,78 +199,102 @@ public class ReuseLibraryUIUtils { ...@@ -184,78 +199,102 @@ public class ReuseLibraryUIUtils {
* (with extracted properties from the given {@link ReuseElementSpec} and * (with extracted properties from the given {@link ReuseElementSpec} and
* title). * title).
* *
* @param referencingSpec The reuse specification that has the information about * @param referencingSpec
* the missing reuse library * The reuse specification that has the information about
* @param dialogTitle The title for the dialog * the missing reuse library
* @param dialogTitle
* The title for the dialog
*/ */
public static void warnOfMissingLib(ReuseElementSpec referencingSpec, String dialogTitle) { public static void warnOfMissingLib(ReuseElementSpec referencingSpec, String dialogTitle) {
List<String> textLines = new ArrayList<String>(); List<String> textLines = new ArrayList<String>();
textLines.add("The selected library does not exist in the library directory."); textLines.add("The selected library does not exist in the library directory.");
textLines.add("\nPlease add it there and repeat."); textLines.add("\nPlease add it there and repeat.");
textLines.add("\nMissing library (UUID and name): " textLines.add("\nMissing library (UUID and name): " + getLibraryIDNameFormat(
+ getLibraryIDNameFormat(referencingSpec.getSourceLibUUID(), referencingSpec.getSourceLibName())); referencingSpec.getSourceLibUUID(), referencingSpec.getSourceLibName()));
textLines.add("\nLibrary directory location: " + REUSE_PROJECT_DIR.getAbsolutePath()); textLines.add("\nLibrary directory location: " + REUSE_PROJECT_DIR.getAbsolutePath());
showWarning(dialogTitle + " - Missing Library", join("\n", textLines)); showWarning(dialogTitle + " - Missing Library", join("\n", textLines));
} }
/**
* Displays a warning message to the user about a failed action due to a missing reuse element
* for it.
*
* @param currentAction
* The action description that has failed
* @param dialogTitle
* The title for the dialog
*/
public static void warnOfDeletedReuseElem(String currentAction, String dialogTitle) {
List<String> textLines = new ArrayList<String>();
textLines.add(
"The following action could not successfully be performed since the initially selected reuse element for this action does not exist anymore.");
textLines.add("\nFailed action: '" + currentAction + "'.");
textLines.add(
"\nPlease, do not delete a reuse element as long as your chosen action for it has not fully terminated.");
showWarning(dialogTitle + " - Missing Element", join("\n", textLines));
}
/** /**
* Manages the external references (like user-defined functions specified * Manages the external references (like user-defined functions specified
* externally in a data dictionary) of the given reuse element. Currently, this * externally in a data dictionary) of the given reuse element. Currently, this
* means to inform the user about existing ones. * means to inform the user about existing ones.
* *
* @param reuseElement The reuse element in which external references should be * @param reuseElement
* managed/searched * The reuse element in which external references should be
* @param actionType The identifier of the current action. Currently * managed/searched
* available: "addToLibrary", "updateInLibrary", * @param actionType
* "updateFromLibrary" * The identifier of the current action. Currently
* @param shellTitle The title for the current shell that will be used as * available: "addToLibrary", "updateInLibrary",
* dialog title * "updateFromLibrary"
* @param shellTitle
* The title for the current shell that will be used as
* dialog title
*/ */
public static void manageExternalReferencesOfReuseElement(EObject reuseElement, String actionType, public static void manageExternalReferencesOfReuseElement(EObject reuseElement,
String shellTitle) { String actionType, String shellTitle) {
// currently, it is just checking for external references and informing the user // Currently, it is just checking for external references and informing the user.
// TODO #4150 : store them automatically together with the reuse element // TODO #4150 : store them automatically together with the reuse element
// inside the library and use them also when the reuse element is used again // inside the library and use them also when the reuse element is used again.
// some text depends on the action during which the external references are // Some text depends on the action during which the external references are
// searched: // searched:
String infoTitle = shellTitle + " - External References"; String infoTitle = shellTitle + " - External References";
String actionText = ""; String actionText = "";
String currentReuseTest = ""; String currentReuseTest = "";
String sourceText = ""; String sourceText = "";
switch (actionType) { switch(actionType) {
case "addToLibrary": case "addToLibrary":
actionText = "added to the library"; actionText = "added to the library";
sourceText = "the added element"; sourceText = "the added element";
break; break;
case "updateInLibrary": case "updateInLibrary":
actionText = "updated in the library"; actionText = "updated in the library";
sourceText = "the source element from the project"; sourceText = "the source element from the project";
break; break;
case "updateFromLibrary": case "updateFromLibrary":
actionText = "updated from the library"; actionText = "updated from the library";
currentReuseTest = " (like now)"; currentReuseTest = " (like now)";
sourceText = "the source element from the library"; sourceText = "the source element from the library";
break; break;
default: default:
showInfo(infoTitle, showInfo(infoTitle, "Cannot manage external references of the reuse element, " +
"Cannot manage external references of the reuse element, " "because the given action type is not known: '" + actionType +
+ "because the given action type is not known: '" + actionType "'\n\nPlease inform a developer to correct this in the source code.");
+ "'\n\nPlease inform a developer to correct this in the source code."); return;
return;
} }
List<EObject> externalRefs = getExternalReferencesOfElement(reuseElement); List<EObject> externalRefs = getExternalReferencesOfElement(reuseElement);
if (!externalRefs.isEmpty()) { if(!externalRefs.isEmpty()) {
String headerText = "The following elements were found as references inside the reuse element you " String headerText =
+ actionText + ".\n\nIn case of reusing this element" + currentReuseTest "The following elements were found as references inside the reuse element you " +
+ ", these referenced elements will be needed in the new environment, too. " actionText + ".\n\nIn case of reusing this element" + currentReuseTest +
+ "Therefore, you might want to add/update these reference elements as well (if not already done).\n"; ", these referenced elements will be needed in the new environment, too. " +
"Therefore, you might want to add/update these reference elements as well (if not already done).\n";
String bodyText = ""; String bodyText = "";
for (EObject externalRef : externalRefs) { for(EObject externalRef : externalRefs) {
bodyText += "\n- " + getReuseElementName(externalRef) + " (" + externalRef.getClass().getSimpleName() bodyText += "\n- " + getReuseElementName(externalRef) + " (" +
+ ")"; externalRef.getClass().getSimpleName() + ")";
if (getReuseElementName(externalRef).equals(getReuseElementName(reuseElement))) { if(getReuseElementName(externalRef).equals(getReuseElementName(reuseElement))) {
bodyText += " [ignore this if it is actually " + sourceText + "]"; bodyText += " [ignore this if it is actually " + sourceText + "]";
} }
} }
...@@ -268,14 +307,18 @@ public class ReuseLibraryUIUtils { ...@@ -268,14 +307,18 @@ public class ReuseLibraryUIUtils {
* Creates and displays a information box with only an OK button. Everything is * Creates and displays a information box with only an OK button. Everything is
* already set except the text for the title, the header and the body. * already set except the text for the title, the header and the body.
* *
* @param windowTitle The title of the dialog window * @param windowTitle
* @param headerText The text of the header between title and body * The title of the dialog window
* @param bodyText The actual text body * @param headerText
* The text of the header between title and body
* @param bodyText
* The actual text body
*/ */
public static void showBasicScrollableInformation(String windowTitle, String headerText, String bodyText) { public static void showBasicScrollableInformation(String windowTitle, String headerText,
String bodyText) {
boolean showSymbol = true; boolean showSymbol = true;
showCustomScrollableAlert(INFORMATION, windowTitle, headerText, bodyText, showSymbol, DIALOG_WINDOW_WIDTH_PREF, showCustomScrollableAlert(INFORMATION, windowTitle, headerText, bodyText, showSymbol,
DIALOG_WINDOW_HEIGHT_PREF); DIALOG_WINDOW_WIDTH_PREF, DIALOG_WINDOW_HEIGHT_PREF);
} }
/** /**
...@@ -284,21 +327,29 @@ public class ReuseLibraryUIUtils { ...@@ -284,21 +327,29 @@ public class ReuseLibraryUIUtils {
* the symbol besides the header should be displayed, the actual text body and * the symbol besides the header should be displayed, the actual text body and
* the preferred size of the window (null if nothing is preferred). * the preferred size of the window (null if nothing is preferred).
* *
* @param alertType The alert type like Information, Error, etc. * @param alertType
* @param windowTitle The title of the dialog window * The alert type like Information, Error, etc.
* @param headerText The text of the header between title and body * @param windowTitle
* @param bodyText The actual text body * The title of the dialog window
* @param showSymbol Whether the symbol besides the header text should be * @param headerText
* displayed * The text of the header between title and body
* @param windowPrefWidth Preferred width of the window * @param bodyText
* @param windowPrefHeight Preferred height of the window * The actual text body
* @param showSymbol
* Whether the symbol besides the header text should be
* displayed
* @param windowPrefWidth
* Preferred width of the window
* @param windowPrefHeight
* Preferred height of the window
*/ */
public static void showCustomScrollableAlert(AlertType alertType, String windowTitle, String headerText, public static void showCustomScrollableAlert(AlertType alertType, String windowTitle,
String bodyText, boolean showSymbol, Double windowPrefWidth, Double windowPrefHeight) { String headerText, String bodyText, boolean showSymbol, Double windowPrefWidth,
Double windowPrefHeight) {
Alert alert = new Alert(alertType); Alert alert = new Alert(alertType);
if (!showSymbol) { if(!showSymbol) {
alert.setGraphic(null); alert.setGraphic(null);
} }
alert.setTitle(windowTitle); alert.setTitle(windowTitle);
...@@ -311,17 +362,17 @@ public class ReuseLibraryUIUtils { ...@@ -311,17 +362,17 @@ public class ReuseLibraryUIUtils {
DialogPane dialogPane = alert.getDialogPane(); DialogPane dialogPane = alert.getDialogPane();
Image taskbarIcon = getFXImage(ToolingReuseUIActivator.PLUGIN_ID, "icons/af3_icon64.png"); Image taskbarIcon = getFXImage(ToolingReuseUIActivator.PLUGIN_ID, "icons/af3_icon64.png");
Stage stage = (Stage) dialogPane.getScene().getWindow(); Stage stage = (Stage)dialogPane.getScene().getWindow();
stage.getIcons().add(taskbarIcon); stage.getIcons().add(taskbarIcon);
// use setExpandableContent(area) if the scrollable text should be first hidden // Use setExpandableContent(area) if the scrollable text should be first hidden
// under "Show details". Then, alert.setContentText() can be used to show a // under "Show details". Then, alert.setContentText() can be used to show a
// short message before // short message before.
dialogPane.setContent(area); dialogPane.setContent(area);
if (windowPrefWidth != null && windowPrefWidth > 0.0) { if(windowPrefWidth != null && windowPrefWidth > 0.0) {
dialogPane.setPrefWidth(windowPrefWidth); dialogPane.setPrefWidth(windowPrefWidth);
} }
if (windowPrefHeight != null && windowPrefHeight > 0.0) { if(windowPrefHeight != null && windowPrefHeight > 0.0) {
dialogPane.setPrefHeight(windowPrefHeight); dialogPane.setPrefHeight(windowPrefHeight);
} }
......
Subproject commit 310d1c04f28f6252d5a02dd8fde1b76ae4a4da51
ToolingReuseActivator.java 3a735e7e2c75e9b048f94bf1adeb172b83301639 GREEN ToolingReuseActivator.java 52b9208684334f60ee8c0bc074c86f06f6248227 GREEN
/*-------------------------------------------------------------------------+ /*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH | | Copyright 2023 fortiss GmbH |
| | | |
| Licensed under the Apache License, Version 2.0 (the "License"); | | Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. | | you may not use this file except in compliance with the License. |
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.fortiss.tooling.ext.reuse; package org.fortiss.tooling.ext.reuse;
import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Plugin;
import org.fortiss.tooling.ext.reuse.model.ReuseLibrary;
import org.fortiss.tooling.kernel.service.IConstraintCheckerService;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
/** /**
...@@ -36,6 +38,12 @@ public class ToolingReuseActivator extends Plugin { ...@@ -36,6 +38,12 @@ public class ToolingReuseActivator extends Plugin {
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
super.start(context); super.start(context);
plugin = this; plugin = this;
// Objects within a ReuseLibrary do not need to comply with the constraint checks with which
// they should comply when they are outside of it (in a normal project). This is why the
// ReuseLibrary needs to be registered as an exclusion for all the usual constraint checks.
IConstraintCheckerService ccs = IConstraintCheckerService.getInstance();
ccs.registerTypeAsExcludedParentForConstraintChecks(ReuseLibrary.class);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment