From 114bb25db82f13c8bc2b1d33fe86ae28f3176e67 Mon Sep 17 00:00:00 2001 From: Claudenir Morais Fonseca Date: Thu, 20 Aug 2020 17:39:22 +0200 Subject: [PATCH] Plugin Update Automation (#61) * Retrieve releases from GitHub * Updates release download * Updates interfaces and download * Updates periodic lookup for new releases * Update plugin.xml and general bugfix * Bugfix * Improved plugin toolbar * Extracted nested classes from ViewUtils * General refactoring and update of releases serialization * Refactoring * Refactoring * Refactoring * BugFix Replaces ZonedDateTime serialization to strings * Refactoring * Refactoring * Fixed null pointer bug Co-authored-by: Tiago Prince Sales --- README.md | 24 +- {resources => docs}/faq-id-in-use.png | Bin {resources => docs}/feature-gufo.png | Bin .../feature-meta-properties.png | Bin {resources => docs}/feature-modeling.gif | Bin {resources => docs}/feature-restricte-to.png | Bin {resources => docs}/feature-smart-paint.png | Bin .../feature-suggested-stereotypes.png | Bin {resources => docs}/feature-toolbar.png | Bin {resources => docs}/feature-verification.gif | Bin .../install-plugin-dialog-folder-path.png | Bin {resources => docs}/install-plugin-dialog.png | Bin {resources => docs}/toolbar-help-install.png | Bin pom.xml | 2 +- .../unibz/inf/ontouml/vp/OntoUMLPlugin.java | 7 +- ...es.java => ApplyPropertiesController.java} | 76 +- .../vp/controllers/ApplyStereotype.java | 363 ---- .../ApplyStereotypeController.java | 362 ++++ ...ava => DiagramVerificationController.java} | 17 +- ...OAction.java => GUFOExportController.java} | 29 +- .../controllers/GitHubAccessController.java | 86 + ...tAction.java => JsonExportController.java} | 15 +- ....java => ModelVerificationController.java} | 15 +- .../OntoUMLServerAccessController.java} | 36 +- .../vp/controllers/PaintModelAction.java | 37 - .../ReloadClassesActionController.java | 19 - .../controllers/ReloadClassesController.java | 76 + ...Action.java => ReportErrorController.java} | 10 +- ...ction.java => SettingsMenuController.java} | 4 +- .../SmartModellingController.java} | 67 +- ...ction.java => UpdatePluginController.java} | 72 +- .../constraints/AssociationConstraints.java | 84 - .../constraints/ClassConstraints.java | 92 - .../ontouml/vp/listeners/DiagramListener.java | 8 +- .../vp/listeners/IssueLogMenuListener.java | 55 + .../ontouml/vp/listeners/ModelListener.java | 74 +- .../ontouml/vp/listeners/ProjectListener.java | 59 +- .../inf/ontouml/vp/model/Configurations.java | 244 +++ .../inf/ontouml/vp/model/GitHubRelease.java | 108 ++ .../ontouml/vp/model/GitHubReleaseAsset.java | 74 + .../ProjectConfigurations.java | 2 +- .../vp/{utils => model}/ServerRequest.java | 2 +- .../vp/model/{ => uml}/Association.java | 2 +- .../vp/model/{ => uml}/AssociationClass.java | 6 +- .../inf/ontouml/vp/model/{ => uml}/Class.java | 38 +- .../vp/model/{ => uml}/Generalization.java | 2 +- .../vp/model/{ => uml}/GeneralizationSet.java | 2 +- .../ontouml/vp/model/{ => uml}/Literal.java | 2 +- .../inf/ontouml/vp/model/{ => uml}/Model.java | 2 +- .../vp/model/{ => uml}/ModelElement.java | 12 +- .../ontouml/vp/model/{ => uml}/Package.java | 8 +- .../ontouml/vp/model/{ => uml}/Property.java | 2 +- .../ontouml/vp/model/{ => uml}/Reference.java | 2 +- .../ActionIdManager.java} | 82 +- .../ontouml/vp/utils/CollectionAdapter.java | 29 - .../inf/ontouml/vp/utils/Configurations.java | 156 -- .../vp/utils/OntoUMLConstraintsManager.java | 110 ++ ...tColoring.java => SmartColoringUtils.java} | 60 +- ...typeUtils.java => StereotypesManager.java} | 3 +- .../{ViewUtils.java => ViewManagerUtils.java} | 309 ++-- .../ontouml/vp/views/ConfigurationsView.java | 4 +- ...ortToGUFOView.java => GUFOExportView.java} | 97 +- .../ontouml/vp/views/HTMLEnabledMessage.java | 9 +- .../inf/ontouml/vp/views/IssueLogMenu.java | 60 + .../inf/ontouml/vp/views/JCheckBoxTree.java | 1623 +++++++++-------- .../unibz/inf/ontouml/vp/views/NameUtil.java | 81 - .../inf/ontouml/vp/views/ProgressPanel.java | 6 +- .../vp/views/SelectMultipleOptionsDialog.java | 202 -- .../vp/views/SelectRestrictionsView.java | 197 ++ ...{SetOrderDialog.java => SetOrderView.java} | 41 +- src/main/resources/plugin.xml | 242 ++- 71 files changed, 2921 insertions(+), 2587 deletions(-) rename {resources => docs}/faq-id-in-use.png (100%) rename {resources => docs}/feature-gufo.png (100%) rename {resources => docs}/feature-meta-properties.png (100%) rename {resources => docs}/feature-modeling.gif (100%) rename {resources => docs}/feature-restricte-to.png (100%) rename {resources => docs}/feature-smart-paint.png (100%) rename {resources => docs}/feature-suggested-stereotypes.png (100%) rename {resources => docs}/feature-toolbar.png (100%) rename {resources => docs}/feature-verification.gif (100%) rename {resources => docs}/install-plugin-dialog-folder-path.png (100%) rename {resources => docs}/install-plugin-dialog.png (100%) rename {resources => docs}/toolbar-help-install.png (100%) rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{ApplyProperties.java => ApplyPropertiesController.java} (67%) delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotype.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{DiagramVerificationAction.java => DiagramVerificationController.java} (81%) rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{ExportToGUFOAction.java => GUFOExportController.java} (87%) create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{ModelExportAction.java => JsonExportController.java} (88%) rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{ModelVerificationAction.java => ModelVerificationController.java} (81%) rename src/main/java/it/unibz/inf/ontouml/vp/{utils/OntoUMLServerUtils.java => controllers/OntoUMLServerAccessController.java} (84%) delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/controllers/PaintModelAction.java delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesActionController.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{ReportErrorAction.java => ReportErrorController.java} (73%) rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{OpenConfigurationsAction.java => SettingsMenuController.java} (96%) rename src/main/java/it/unibz/inf/ontouml/vp/{utils/SmartModelling.java => controllers/SmartModellingController.java} (82%) rename src/main/java/it/unibz/inf/ontouml/vp/controllers/{UpdatePluginAction.java => UpdatePluginController.java} (51%) delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/features/constraints/AssociationConstraints.java delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ClassConstraints.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/model/Configurations.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/model/GitHubRelease.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/model/GitHubReleaseAsset.java rename src/main/java/it/unibz/inf/ontouml/vp/{utils => model}/ProjectConfigurations.java (99%) rename src/main/java/it/unibz/inf/ontouml/vp/{utils => model}/ServerRequest.java (87%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Association.java (99%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/AssociationClass.java (96%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Class.java (92%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Generalization.java (98%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/GeneralizationSet.java (99%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Literal.java (97%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Model.java (99%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/ModelElement.java (95%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Package.java (93%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Property.java (99%) rename src/main/java/it/unibz/inf/ontouml/vp/model/{ => uml}/Reference.java (95%) rename src/main/java/it/unibz/inf/ontouml/vp/{features/constraints/ActionIds.java => utils/ActionIdManager.java} (85%) delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/utils/CollectionAdapter.java delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/utils/Configurations.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLConstraintsManager.java rename src/main/java/it/unibz/inf/ontouml/vp/utils/{SmartColoring.java => SmartColoringUtils.java} (69%) rename src/main/java/it/unibz/inf/ontouml/vp/utils/{StereotypeUtils.java => StereotypesManager.java} (99%) rename src/main/java/it/unibz/inf/ontouml/vp/utils/{ViewUtils.java => ViewManagerUtils.java} (74%) rename src/main/java/it/unibz/inf/ontouml/vp/views/{ExportToGUFOView.java => GUFOExportView.java} (92%) create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/views/IssueLogMenu.java delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/views/NameUtil.java delete mode 100644 src/main/java/it/unibz/inf/ontouml/vp/views/SelectMultipleOptionsDialog.java create mode 100644 src/main/java/it/unibz/inf/ontouml/vp/views/SelectRestrictionsView.java rename src/main/java/it/unibz/inf/ontouml/vp/views/{SetOrderDialog.java => SetOrderView.java} (76%) diff --git a/README.md b/README.md index 97f63221..32a39489 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,13 @@ Stereotypes and meta-properties that are essential to OntoUML modeling are easil Notice that beyond the full list of stereotypes, a dynamic list of stereotypes is also available. This dynamic list is usually preferred during modeling as it filters wrong stereotypes for your class or association based on, respectively, their super/sub classes and their associated classes. The full list, however, tends to provide a faster and more flexible option during model fixing and refactoring. -![GIF showing a OntoUML model being edited](./resources/feature-modeling.gif) +![GIF showing a OntoUML model being edited](./docs/feature-modeling.gif) -![A screenshot of a suggested list of stereotypes in a context menu](./resources/feature-suggested-stereotypes.png) +![A screenshot of a suggested list of stereotypes in a context menu](./docs/feature-suggested-stereotypes.png) -![A screenshot of meta-properties editing in context menu](./resources/feature-meta-properties.png) +![A screenshot of meta-properties editing in context menu](./docs/feature-meta-properties.png) -![A screenshot of restricted instances menu selection](./resources/feature-restricte-to.png) +![A screenshot of restricted instances menu selection](./docs/feature-restricte-to.png) Try selecting multiple elements to fast update your models! @@ -49,7 +49,7 @@ Try selecting multiple elements to fast update your models! Automatic diagram painting based on the possible instances of classes with highlighted ultimate sortals (i.e., «kind», «collective», «quantity», «relator», «mode», and «quality») for improved model readability. -![A screenshot of an automatically painted diagram](./resources/feature-smart-paint.png) +![A screenshot of an automatically painted diagram](./docs/feature-smart-paint.png) #### Smart Modeling @@ -63,7 +63,7 @@ Automatic verification of OntoUML syntactical rules which are reported to the us The Diagram Verification feature performs the verification of the whole model but only displays issues about elements present in the currently open diagram, facilitating the user's task of fixing models. -![A gif exemplifying the model verification feature](./resources/feature-verification.gif) +![A gif exemplifying the model verification feature](./docs/feature-verification.gif) #### Model Transformation to OWL with gUFO @@ -73,7 +73,7 @@ Users must select the elements that shall be exported to gUFO either selecting f **WARNING**: the transformation feature require the presence of no verification errors among the exported entities. In addition, partial transformations of the model should be executed with care as they may introduce violations of some syntactical constraint. -![A screenshot showing the "transformation to gUFO" window](./resources/feature-gufo.png) +![A screenshot showing the "transformation to gUFO" window](./docs/feature-gufo.png) #### Continuous Updates @@ -81,7 +81,7 @@ The cloud-based features offered in the plugin are periodically updated. Updates And last, but not least, this project is supported by the [OntoUML.org](https://ontouml.org/) community and its set of features will only grow, incorporating new and updated OntoUML technologies. -![A screenshot showing the toolbar of the OntoUML plugin](./resources/feature-toolbar.png) +![A screenshot showing the toolbar of the OntoUML plugin](./docs/feature-toolbar.png) In order to update to a new version of the plugin, please download the latest [release](https://github.com/OntoUML/ontouml-vp-plugin/releases) as a ZIP file and select it through the "Update Plugin" button in the plugin (available from version 0.3.0). @@ -93,9 +93,9 @@ ___ To **install** or **update** the **OntoUML Plugin for Visual Paradigm**, please go to our [releases page](https://github.com/OntoUML/ontouml-vp-plugin/releases) and download the ZIP file `ontouml-vp-plugin` in the latest release. Then go to `Help > Install Plugin` in the top of your window and, after clicking `Install from a zip of plugin` and `Next`, select the download release. -![Install plugin window](./resources/toolbar-help-install.png) +![Install plugin window](./docs/toolbar-help-install.png) -![Install plugin window](./resources/install-plugin-dialog.png) +![Install plugin window](./docs/install-plugin-dialog.png) For more details, check out this [guide](https://knowhow.visual-paradigm.com/openapi/how-to-deploy-plugins-to-vp-application/). @@ -229,11 +229,11 @@ ___ ### Why do I get the error message "The ID [...] is already in use"? -![Error message: ID already in use](./resources/faq-id-in-use.png) +![Error message: ID already in use](./docs/faq-id-in-use.png) Each Visual Paradigm plugin must (i) have an ID, and (ii) be installed in a specific folder. If you are updating to a new version of the plugin, it may occur that the name of the folder has changed. In this case, Visual Paradigm will think that you are trying to install a new plugin with an ID already in use instead of updating it. -![Install plugin window](./resources/install-plugin-dialog-folder-path.png) +![Install plugin window](./docs/install-plugin-dialog-folder-path.png) To solve this issue, go to the `plugins` folder listed in the "Install Plugin" window (see above) and delete your old plugin folder before installing the new version. You may be required to re-open the application for that to take effect. diff --git a/resources/faq-id-in-use.png b/docs/faq-id-in-use.png similarity index 100% rename from resources/faq-id-in-use.png rename to docs/faq-id-in-use.png diff --git a/resources/feature-gufo.png b/docs/feature-gufo.png similarity index 100% rename from resources/feature-gufo.png rename to docs/feature-gufo.png diff --git a/resources/feature-meta-properties.png b/docs/feature-meta-properties.png similarity index 100% rename from resources/feature-meta-properties.png rename to docs/feature-meta-properties.png diff --git a/resources/feature-modeling.gif b/docs/feature-modeling.gif similarity index 100% rename from resources/feature-modeling.gif rename to docs/feature-modeling.gif diff --git a/resources/feature-restricte-to.png b/docs/feature-restricte-to.png similarity index 100% rename from resources/feature-restricte-to.png rename to docs/feature-restricte-to.png diff --git a/resources/feature-smart-paint.png b/docs/feature-smart-paint.png similarity index 100% rename from resources/feature-smart-paint.png rename to docs/feature-smart-paint.png diff --git a/resources/feature-suggested-stereotypes.png b/docs/feature-suggested-stereotypes.png similarity index 100% rename from resources/feature-suggested-stereotypes.png rename to docs/feature-suggested-stereotypes.png diff --git a/resources/feature-toolbar.png b/docs/feature-toolbar.png similarity index 100% rename from resources/feature-toolbar.png rename to docs/feature-toolbar.png diff --git a/resources/feature-verification.gif b/docs/feature-verification.gif similarity index 100% rename from resources/feature-verification.gif rename to docs/feature-verification.gif diff --git a/resources/install-plugin-dialog-folder-path.png b/docs/install-plugin-dialog-folder-path.png similarity index 100% rename from resources/install-plugin-dialog-folder-path.png rename to docs/install-plugin-dialog-folder-path.png diff --git a/resources/install-plugin-dialog.png b/docs/install-plugin-dialog.png similarity index 100% rename from resources/install-plugin-dialog.png rename to docs/install-plugin-dialog.png diff --git a/resources/toolbar-help-install.png b/docs/toolbar-help-install.png similarity index 100% rename from resources/toolbar-help-install.png rename to docs/toolbar-help-install.png diff --git a/pom.xml b/pom.xml index b997b2c3..3c1cbb7e 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ it.unibz.inf.ontouml ontouml-vp-plugin - 0.3.1-SNAPSHOT + 0.4.0-alpha1 OntoUML 2 Plugin for Visual Paradigm diff --git a/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java b/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java index 303a1f50..308dc96e 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java @@ -9,7 +9,6 @@ import com.vp.plugin.model.factory.IModelElementFactory; import it.unibz.inf.ontouml.vp.listeners.ProjectListener; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; /** * Implementation of VPPlugin responsible for configuring OntoUML Plugin's @@ -20,10 +19,12 @@ */ public class OntoUMLPlugin implements VPPlugin { - public static final String PLUGIN_VERSION_RELEASE = "0.3.1"; + public static final String PLUGIN_VERSION_RELEASE = "0.4.0alpha1"; public static final String PLUGIN_ID = "it.unibz.inf.ontouml.vp"; public static final String PLUGIN_NAME = "OntoUML Plugin"; public static final String PLUGIN_REPO = "https://github.com/OntoUML/ontouml-vp-plugin/"; + public static final String PLUGIN_REPO_OWNER = "OntoUML"; + public static final String PLUGIN_REPO_NAME = "ontouml-vp-plugin"; public static IModelElement[] allModelElements; public static boolean isPluginActive; @@ -86,7 +87,7 @@ public static boolean getConfigWindowOpen() { } public static void reload() { - ViewUtils.log("Reloading plugin: "+PLUGIN_ID); +// ViewUtils.log("Reloading plugin: "+PLUGIN_ID); ApplicationManager.instance().reloadPluginClasses(PLUGIN_ID); // TODO: try to integrate listener to the reload process } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyProperties.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java similarity index 67% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyProperties.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java index 89f7f66b..2e747c36 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyProperties.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyPropertiesController.java @@ -16,13 +16,13 @@ import com.vp.plugin.model.ITaggedValue; import com.vp.plugin.model.factory.IModelElementFactory; -import it.unibz.inf.ontouml.vp.features.constraints.ActionIds; -import it.unibz.inf.ontouml.vp.model.Class; -import it.unibz.inf.ontouml.vp.model.ModelElement; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; -import it.unibz.inf.ontouml.vp.views.SelectMultipleOptionsDialog; -import it.unibz.inf.ontouml.vp.views.SetOrderDialog; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.uml.Class; +import it.unibz.inf.ontouml.vp.model.uml.ModelElement; +import it.unibz.inf.ontouml.vp.utils.ActionIdManager; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; +import it.unibz.inf.ontouml.vp.views.SelectRestrictionsView; +import it.unibz.inf.ontouml.vp.views.SetOrderView; /** * Implementation of context sensitive action of change OntoUML stereotypes in model elements. @@ -30,7 +30,7 @@ * @author Claudenir Fonseca * @author Victor Viola */ -public class ApplyProperties implements VPContextActionController { +public class ApplyPropertiesController implements VPContextActionController { @Override public void performAction(VPAction action, VPContext context, ActionEvent event) { @@ -44,30 +44,30 @@ public void performAction(VPAction action, VPContext context, ActionEvent event) final IClass clickedClass = (IClass) context.getModelElement(); switch (action.getActionId()) { - case ActionIds.PROPERTY_SET_RESTRICTED_TO: + case ActionIdManager.PROPERTY_SET_RESTRICTED_TO: this.setRestrictedTo(context, clickedClass); break; - case ActionIds.PROPERTY_SET_IS_ABSTRACT: + case ActionIdManager.PROPERTY_SET_IS_ABSTRACT: final boolean isAbstract = clickedClass.isAbstract(); forEachSelectedClass(context, cla -> cla.setAbstract(!isAbstract)); break; - case ActionIds.PROPERTY_SET_IS_DERIVED: + case ActionIdManager.PROPERTY_SET_IS_DERIVED: final boolean isDerived = ModelElement.getIsDerived(clickedClass); forEachSelectedClass(context, selected -> { ModelElement.setIsDerived(selected, !isDerived); }); break; - case ActionIds.PROPERTY_SET_IS_EXTENSIONAL: - setBooleanTaggedValue(context, clickedClass, StereotypeUtils.PROPERTY_IS_EXTENSIONAL); + case ActionIdManager.PROPERTY_SET_IS_EXTENSIONAL: + setBooleanTaggedValue(context, clickedClass, StereotypesManager.PROPERTY_IS_EXTENSIONAL); break; - case ActionIds.PROPERTY_SET_IS_POWERTYPE: - setBooleanTaggedValue(context, clickedClass, StereotypeUtils.PROPERTY_IS_POWERTYPE); + case ActionIdManager.PROPERTY_SET_IS_POWERTYPE: + setBooleanTaggedValue(context, clickedClass, StereotypesManager.PROPERTY_IS_POWERTYPE); break; - case ActionIds.PROPERTY_SET_ORDER: + case ActionIdManager.PROPERTY_SET_ORDER: setOrderProperty(context, clickedClass); break; } @@ -83,22 +83,22 @@ public void update(VPAction action, VPContext context) { } final IClass _class = (IClass) context.getModelElement(); - final String stereotype = StereotypeUtils.getUniqueStereotypeName(_class); - final Set allClassStereotypes = StereotypeUtils.getOntoUMLClassStereotypeNames(); + final String stereotype = StereotypesManager.getUniqueStereotypeName(_class); + final Set allClassStereotypes = StereotypesManager.getOntoUMLClassStereotypeNames(); switch (action.getActionId()) { - case ActionIds.PROPERTY_SET_RESTRICTED_TO: + case ActionIdManager.PROPERTY_SET_RESTRICTED_TO: if (allClassStereotypes.contains(stereotype)) { final boolean isSmartModelingEnabled = Configurations.getInstance() .getProjectConfigurations() .isSmartModellingEnabled(); final List nonFixedRestrictedTo = - Arrays.asList(StereotypeUtils.STR_CATEGORY, - StereotypeUtils.STR_MIXIN, - StereotypeUtils.STR_PHASE_MIXIN, - StereotypeUtils.STR_ROLE_MIXIN, - StereotypeUtils.STR_HISTORICAL_ROLE_MIXIN); + Arrays.asList(StereotypesManager.STR_CATEGORY, + StereotypesManager.STR_MIXIN, + StereotypesManager.STR_PHASE_MIXIN, + StereotypesManager.STR_ROLE_MIXIN, + StereotypesManager.STR_HISTORICAL_ROLE_MIXIN); action.setEnabled(!isSmartModelingEnabled || nonFixedRestrictedTo.contains(stereotype)); @@ -106,24 +106,24 @@ public void update(VPAction action, VPContext context) { action.setEnabled(false); } break; - case ActionIds.PROPERTY_SET_IS_ABSTRACT: + case ActionIdManager.PROPERTY_SET_IS_ABSTRACT: action.setEnabled(true); action.setSelected(_class.isAbstract()); break; - case ActionIds.PROPERTY_SET_IS_DERIVED: + case ActionIdManager.PROPERTY_SET_IS_DERIVED: action.setEnabled(true); action.setSelected(ModelElement.getIsDerived(_class)); break; - case ActionIds.PROPERTY_SET_IS_EXTENSIONAL: - action.setEnabled(StereotypeUtils.STR_COLLECTIVE.equals(stereotype)); + case ActionIdManager.PROPERTY_SET_IS_EXTENSIONAL: + action.setEnabled(StereotypesManager.STR_COLLECTIVE.equals(stereotype)); action.setSelected(Class.getIsExtensional(_class)); break; - case ActionIds.PROPERTY_SET_IS_POWERTYPE: - action.setEnabled(StereotypeUtils.STR_TYPE.equals(stereotype)); + case ActionIdManager.PROPERTY_SET_IS_POWERTYPE: + action.setEnabled(StereotypesManager.STR_TYPE.equals(stereotype)); action.setSelected(Class.getIsPowertype(_class)); break; - case ActionIds.PROPERTY_SET_ORDER: - action.setEnabled(_class.hasStereotype(StereotypeUtils.STR_TYPE)); + case ActionIdManager.PROPERTY_SET_ORDER: + action.setEnabled(_class.hasStereotype(StereotypesManager.STR_TYPE)); break; } } @@ -150,11 +150,11 @@ private void forEachSelectedClass(VPContext context, Consumer consumer) } private void setBooleanTaggedValue(VPContext context, IClass clickedClass, String metaProperty) { - final ITaggedValue booleanTaggedValue = StereotypeUtils.reapplyStereotypeAndGetTaggedValue(clickedClass, metaProperty); + final ITaggedValue booleanTaggedValue = StereotypesManager.reapplyStereotypeAndGetTaggedValue(clickedClass, metaProperty); final boolean value = booleanTaggedValue != null && Boolean.parseBoolean(booleanTaggedValue.getValueAsString()); forEachSelectedClass(context, cla -> { - ITaggedValue taggedValue = StereotypeUtils.reapplyStereotypeAndGetTaggedValue(cla, metaProperty); + ITaggedValue taggedValue = StereotypesManager.reapplyStereotypeAndGetTaggedValue(cla, metaProperty); if (taggedValue == null) return; @@ -165,17 +165,17 @@ private void setBooleanTaggedValue(VPContext context, IClass clickedClass, Strin private void setOrderProperty(VPContext context, IClass clickedClass) { final ITaggedValue baseTaggedValue = - StereotypeUtils.reapplyStereotypeAndGetTaggedValue(clickedClass, StereotypeUtils.PROPERTY_ORDER); + StereotypesManager.reapplyStereotypeAndGetTaggedValue(clickedClass, StereotypesManager.PROPERTY_ORDER); if (baseTaggedValue == null) return; - final SetOrderDialog dialog = new SetOrderDialog(baseTaggedValue.getValueAsString()); + final SetOrderView dialog = new SetOrderView(baseTaggedValue.getValueAsString()); ApplicationManager.instance().getViewManager().showDialog(dialog); final String order = dialog.getOrder(); forEachSelectedClass(context, cla -> { - ITaggedValue taggedValue = StereotypeUtils.reapplyStereotypeAndGetTaggedValue(cla, StereotypeUtils.PROPERTY_ORDER); + ITaggedValue taggedValue = StereotypesManager.reapplyStereotypeAndGetTaggedValue(cla, StereotypesManager.PROPERTY_ORDER); if (taggedValue == null) return; @@ -189,7 +189,7 @@ private void setRestrictedTo(VPContext context, IClass clickedClass) { String currentRestrictions = Class.getRestrictedTo(clickedClass); currentRestrictions = currentRestrictions == null ? "" : currentRestrictions; - final SelectMultipleOptionsDialog dialog = new SelectMultipleOptionsDialog(currentRestrictions); + final SelectRestrictionsView dialog = new SelectRestrictionsView(currentRestrictions); ApplicationManager.instance().getViewManager().showDialog(dialog); final String newRestrictions = dialog.getSelectedValues(); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotype.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotype.java deleted file mode 100644 index 8a6f1811..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotype.java +++ /dev/null @@ -1,363 +0,0 @@ -package it.unibz.inf.ontouml.vp.controllers; - -import java.awt.event.ActionEvent; -import java.util.LinkedList; - -import com.vp.plugin.ApplicationManager; -import com.vp.plugin.DiagramManager; -import com.vp.plugin.action.VPAction; -import com.vp.plugin.action.VPContext; -import com.vp.plugin.action.VPContextActionController; -import com.vp.plugin.diagram.IDiagramElement; -import com.vp.plugin.model.IAssociation; -import com.vp.plugin.model.IClass; -import com.vp.plugin.model.IModelElement; -import com.vp.plugin.model.ISimpleRelationship; -import com.vp.plugin.model.factory.IModelElementFactory; - -import it.unibz.inf.ontouml.vp.features.constraints.ActionIds; -import it.unibz.inf.ontouml.vp.model.Class; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.SmartModelling; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; - -/** - * Implementation of context sensitive action of change OntoUML stereotypes in model elements. - * - * @author Claudenir Fonseca - * @author Victor Viola - */ -public class ApplyStereotype implements VPContextActionController { - - @Override - public void performAction(VPAction action, VPContext context, ActionEvent event) { - IDiagramElement[] diagramElements = ApplicationManager.instance() - .getDiagramManager() - .getActiveDiagram() - .getSelectedDiagramElement(); - - if (diagramElements == null) { - applyStereotype(action, context.getModelElement()); - return; - } - - IModelElement clickedElement = context.getModelElement(); - - for (IDiagramElement diagramElement : diagramElements) { - IModelElement modelElement = diagramElement.getModelElement(); - - if (modelElement.getModelType().equals(clickedElement.getModelType())) - applyStereotype(action, modelElement); - } - } - - // TODO: change this method to be independent of diagram elements - @Override - public void update(VPAction action, VPContext context) { - action.setEnabled(true); - - if (action.getActionId().contains("fixedMenu")) { return ; } - - if ( - context.getModelElement().getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS) && - !isClassSelectionAllowed() - ) { - action.setEnabled(false); - } - - final DiagramManager dm = ApplicationManager - .instance().getDiagramManager(); - IDiagramElement[] diagramElements = - dm.getActiveDiagram() != null ? - dm.getActiveDiagram().getSelectedDiagramElement() : - null; - - if (diagramElements == null) { - defineActionBehavior(action, context.getModelElement()); - return; - } - - for (IDiagramElement diagramElement : diagramElements) { - if (diagramElement.getModelElement().getModelType().equals(context.getModelElement().getModelType())) - defineActionBehavior(action, diagramElement.getModelElement()); - } - - } - - private void applyStereotype(VPAction action, IModelElement element) { - switch (action.getActionId()) { - case ActionIds.TYPE: - case ActionIds.TYPE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_TYPE); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.HISTORICAL_ROLE: - case ActionIds.HISTORICAL_ROLE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_HISTORICAL_ROLE); - break; - case ActionIds.HISTORICAL_ROLE_MIXIN: - case ActionIds.HISTORICAL_ROLE_MIXIN_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_HISTORICAL_ROLE_MIXIN); - break; - case ActionIds.EVENT: - case ActionIds.EVENT_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_EVENT); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.SITUATION: - case ActionIds.SITUATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_SITUATION); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.ENUMERATION: - case ActionIds.ENUMERATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_ENUMERATION); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.DATATYPE: - case ActionIds.DATATYPE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_DATATYPE); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.SUBKIND: - case ActionIds.SUBKIND_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_SUBKIND); - break; - case ActionIds.ROLE_MIXIN: - case ActionIds.ROLE_MIXIN_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_ROLE_MIXIN); - break; - case ActionIds.ROLE: - case ActionIds.ROLE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_ROLE); - break; - case ActionIds.RELATOR: - case ActionIds.RELATOR_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_RELATOR); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.QUANTITY: - case ActionIds.QUANTITY_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_QUANTITY); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.QUALITY: - case ActionIds.QUALITY_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_QUALITY); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.PHASE_MIXIN: - case ActionIds.PHASE_MIXIN_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_PHASE_MIXIN); - break; - case ActionIds.PHASE: - case ActionIds.PHASE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_PHASE); - break; - case ActionIds.MODE: - case ActionIds.MODE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_MODE); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.MIXIN: - case ActionIds.MIXIN_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_MIXIN); - break; - case ActionIds.KIND: - case ActionIds.KIND_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_KIND); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.COLLECTIVE: - case ActionIds.COLLECTIVE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_COLLECTIVE); - Class.setDefaultRestrictedTo((IClass) element); - break; - case ActionIds.CATEGORY: - case ActionIds.CATEGORY_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_CATEGORY); - break; - case ActionIds.INSTANTIATION: - case ActionIds.INSTANTIATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_INSTANTIATION); - break; - case ActionIds.TERMINATION: - case ActionIds.TERMINATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_TERMINATION); - break; - case ActionIds.PARTICIPATIONAL: - case ActionIds.PARTICIPATIONAL_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_PARTICIPATIONAL); - break; - case ActionIds.PARTICIPATION: - case ActionIds.PARTICIPATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_PARTICIPATION); - break; - case ActionIds.HISTORICAL_DEPENDENCE: - case ActionIds.HISTORICAL_DEPENDENCE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_HISTORICAL_DEPENDENCE); - break; - case ActionIds.CREATION: - case ActionIds.CREATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_CREATION); - break; - case ActionIds.MANIFESTATION: - case ActionIds.MANIFESTATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_MANIFESTATION); - break; - case ActionIds.BRINGS_ABOUT: - case ActionIds.BRINGS_ABOUT_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_BRINGS_ABOUT); - break; - case ActionIds.TRIGGERS: - case ActionIds.TRIGGERS_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_TRIGGERS); - break; - case ActionIds.MATERIAL: - case ActionIds.MATERIAL_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_MATERIAL); - break; - case ActionIds.COMPARATIVE: - case ActionIds.COMPARATIVE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_COMPARATIVE); - break; - case ActionIds.MEDIATION: - case ActionIds.MEDIATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_MEDIATION); - break; - case ActionIds.CHARACTERIZATION: - case ActionIds.CHARACTERIZATION_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_CHARACTERIZATION); - break; - case ActionIds.EXTERNAL_DEPENDENCE: - case ActionIds.EXTERNAL_DEPENDENCE_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_EXTERNAL_DEPENDENCE); - break; - case ActionIds.COMPONENT_OF: - case ActionIds.COMPONENT_OF_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_COMPONENT_OF); - break; - case ActionIds.MEMBER_OF: - case ActionIds.MEMBER_OF_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_MEMBER_OF); - break; - case ActionIds.SUB_COLLECTION_OF: - case ActionIds.SUB_COLLECTION_OF_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_SUB_COLLECTION_OF); - break; - case ActionIds.SUB_QUANTITY_OF: - case ActionIds.SUB_QUANTITY_OF_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_SUB_QUANTITY_OF); - break; - case ActionIds.BEGIN: - case ActionIds.BEGIN_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_BEGIN); - break; - case ActionIds.END: - case ActionIds.END_FIXED: - StereotypeUtils.applyStereotype(element, StereotypeUtils.STR_END); - break; - } - - boolean isSmartModelingEnabled = Configurations.getInstance().getProjectConfigurations() - .isSmartModellingEnabled(); - boolean isClass = element.getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS); - boolean isAssociation = element.getModelType().equals(IModelElementFactory.MODEL_TYPE_ASSOCIATION); - - if (isSmartModelingEnabled && isClass) - SmartModelling.setClassMetaProperties((IClass) element); - - if (isSmartModelingEnabled && isAssociation) - SmartModelling.setAssociationMetaProperties((IAssociation) element); - } - - private void defineActionBehavior(VPAction action, IModelElement element) { - - if (element.getModelType().equals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { - final IAssociation association = (IAssociation) element; - SmartModelling.manageAssociationStereotypes(association, action); - return; - } - - if (element.getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS)) { - final IClass _class = (IClass) element; - SmartModelling.manageClassStereotypes(_class, action); - return; - } - } - - private boolean isClassSelectionAllowed() { - - final DiagramManager dm = ApplicationManager.instance() - .getDiagramManager(); - IDiagramElement[] diagramElements = - dm.getActiveDiagram() != null ? - dm.getActiveDiagram().getSelectedDiagramElement() : - null ; - LinkedList superClasses = new LinkedList<>(); - - if (diagramElements == null) - return true; - - if (diagramElements.length == 1) - return true; - - //build list of Ids of all classes selected - for (IDiagramElement diagramElement : diagramElements) { - - ISimpleRelationship[] relationshipsTo = diagramElement.getModelElement().toToRelationshipArray(); - - for (int i = 0; relationshipsTo != null && i < relationshipsTo.length; i++) { - ISimpleRelationship relationshipTo = relationshipsTo[i]; - String superClassType = relationshipTo.getFrom() != null ? relationshipTo.getFrom().getModelType() : ""; - - if (!(superClassType.equals(IModelElementFactory.MODEL_TYPE_CLASS))) - continue; - - IClass superClass = (IClass) relationshipTo.getFrom(); - - superClasses.add(superClass.getId()); - } - } - - //Iterates over the list of the superclasses Id - //then iterate over the list again to count if the id - //was inserted the same amount as the amount of selected classes - int counter = 0; - - for (int i = 0; i < superClasses.size(); i++) { - String id = superClasses.get(i); - - for (int j = 0; j < superClasses.size(); j++) { - String idAux = superClasses.get(j); - - if (id.equals(idAux)) - counter++; - } - - if (counter == countClassesSelected()) - return true; - else - counter = 0; - } - - return false; - } - - private int countClassesSelected() { - - IDiagramElement[] diagramElements = ApplicationManager.instance().getDiagramManager().getActiveDiagram().getSelectedDiagramElement(); - int count = 0; - - if (diagramElements == null) - return count; - - for (IDiagramElement diagramElement : diagramElements) { - if (diagramElement.getModelElement().getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS)) - count++; - } - - return count++; - } - -} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java new file mode 100644 index 00000000..e59e8cfd --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ApplyStereotypeController.java @@ -0,0 +1,362 @@ +package it.unibz.inf.ontouml.vp.controllers; + +import java.awt.event.ActionEvent; +import java.util.LinkedList; + +import com.vp.plugin.ApplicationManager; +import com.vp.plugin.DiagramManager; +import com.vp.plugin.action.VPAction; +import com.vp.plugin.action.VPContext; +import com.vp.plugin.action.VPContextActionController; +import com.vp.plugin.diagram.IDiagramElement; +import com.vp.plugin.model.IAssociation; +import com.vp.plugin.model.IClass; +import com.vp.plugin.model.IModelElement; +import com.vp.plugin.model.ISimpleRelationship; +import com.vp.plugin.model.factory.IModelElementFactory; + +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.uml.Class; +import it.unibz.inf.ontouml.vp.utils.ActionIdManager; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; + +/** + * Implementation of context sensitive action of change OntoUML stereotypes in model elements. + * + * @author Claudenir Fonseca + * @author Victor Viola + */ +public class ApplyStereotypeController implements VPContextActionController { + + @Override + public void performAction(VPAction action, VPContext context, ActionEvent event) { + IDiagramElement[] diagramElements = ApplicationManager.instance() + .getDiagramManager() + .getActiveDiagram() + .getSelectedDiagramElement(); + + if (diagramElements == null) { + applyStereotype(action, context.getModelElement()); + return; + } + + IModelElement clickedElement = context.getModelElement(); + + for (IDiagramElement diagramElement : diagramElements) { + IModelElement modelElement = diagramElement.getModelElement(); + + if (modelElement.getModelType().equals(clickedElement.getModelType())) + applyStereotype(action, modelElement); + } + } + + // TODO: change this method to be independent of diagram elements + @Override + public void update(VPAction action, VPContext context) { + action.setEnabled(true); + + if (action.getActionId().contains("fixedMenu")) { return ; } + + if ( + context.getModelElement().getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS) && + !isClassSelectionAllowed() + ) { + action.setEnabled(false); + } + + final DiagramManager dm = ApplicationManager + .instance().getDiagramManager(); + IDiagramElement[] diagramElements = + dm.getActiveDiagram() != null ? + dm.getActiveDiagram().getSelectedDiagramElement() : + null; + + if (diagramElements == null) { + defineActionBehavior(action, context.getModelElement()); + return; + } + + for (IDiagramElement diagramElement : diagramElements) { + if (diagramElement.getModelElement().getModelType().equals(context.getModelElement().getModelType())) + defineActionBehavior(action, diagramElement.getModelElement()); + } + + } + + private void applyStereotype(VPAction action, IModelElement element) { + switch (action.getActionId()) { + case ActionIdManager.TYPE: + case ActionIdManager.TYPE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_TYPE); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.HISTORICAL_ROLE: + case ActionIdManager.HISTORICAL_ROLE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_HISTORICAL_ROLE); + break; + case ActionIdManager.HISTORICAL_ROLE_MIXIN: + case ActionIdManager.HISTORICAL_ROLE_MIXIN_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_HISTORICAL_ROLE_MIXIN); + break; + case ActionIdManager.EVENT: + case ActionIdManager.EVENT_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_EVENT); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.SITUATION: + case ActionIdManager.SITUATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_SITUATION); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.ENUMERATION: + case ActionIdManager.ENUMERATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_ENUMERATION); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.DATATYPE: + case ActionIdManager.DATATYPE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_DATATYPE); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.SUBKIND: + case ActionIdManager.SUBKIND_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_SUBKIND); + break; + case ActionIdManager.ROLE_MIXIN: + case ActionIdManager.ROLE_MIXIN_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_ROLE_MIXIN); + break; + case ActionIdManager.ROLE: + case ActionIdManager.ROLE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_ROLE); + break; + case ActionIdManager.RELATOR: + case ActionIdManager.RELATOR_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_RELATOR); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.QUANTITY: + case ActionIdManager.QUANTITY_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_QUANTITY); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.QUALITY: + case ActionIdManager.QUALITY_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_QUALITY); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.PHASE_MIXIN: + case ActionIdManager.PHASE_MIXIN_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_PHASE_MIXIN); + break; + case ActionIdManager.PHASE: + case ActionIdManager.PHASE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_PHASE); + break; + case ActionIdManager.MODE: + case ActionIdManager.MODE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_MODE); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.MIXIN: + case ActionIdManager.MIXIN_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_MIXIN); + break; + case ActionIdManager.KIND: + case ActionIdManager.KIND_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_KIND); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.COLLECTIVE: + case ActionIdManager.COLLECTIVE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_COLLECTIVE); + Class.setDefaultRestrictedTo((IClass) element); + break; + case ActionIdManager.CATEGORY: + case ActionIdManager.CATEGORY_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_CATEGORY); + break; + case ActionIdManager.INSTANTIATION: + case ActionIdManager.INSTANTIATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_INSTANTIATION); + break; + case ActionIdManager.TERMINATION: + case ActionIdManager.TERMINATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_TERMINATION); + break; + case ActionIdManager.PARTICIPATIONAL: + case ActionIdManager.PARTICIPATIONAL_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_PARTICIPATIONAL); + break; + case ActionIdManager.PARTICIPATION: + case ActionIdManager.PARTICIPATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_PARTICIPATION); + break; + case ActionIdManager.HISTORICAL_DEPENDENCE: + case ActionIdManager.HISTORICAL_DEPENDENCE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_HISTORICAL_DEPENDENCE); + break; + case ActionIdManager.CREATION: + case ActionIdManager.CREATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_CREATION); + break; + case ActionIdManager.MANIFESTATION: + case ActionIdManager.MANIFESTATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_MANIFESTATION); + break; + case ActionIdManager.BRINGS_ABOUT: + case ActionIdManager.BRINGS_ABOUT_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_BRINGS_ABOUT); + break; + case ActionIdManager.TRIGGERS: + case ActionIdManager.TRIGGERS_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_TRIGGERS); + break; + case ActionIdManager.MATERIAL: + case ActionIdManager.MATERIAL_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_MATERIAL); + break; + case ActionIdManager.COMPARATIVE: + case ActionIdManager.COMPARATIVE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_COMPARATIVE); + break; + case ActionIdManager.MEDIATION: + case ActionIdManager.MEDIATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_MEDIATION); + break; + case ActionIdManager.CHARACTERIZATION: + case ActionIdManager.CHARACTERIZATION_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_CHARACTERIZATION); + break; + case ActionIdManager.EXTERNAL_DEPENDENCE: + case ActionIdManager.EXTERNAL_DEPENDENCE_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_EXTERNAL_DEPENDENCE); + break; + case ActionIdManager.COMPONENT_OF: + case ActionIdManager.COMPONENT_OF_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_COMPONENT_OF); + break; + case ActionIdManager.MEMBER_OF: + case ActionIdManager.MEMBER_OF_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_MEMBER_OF); + break; + case ActionIdManager.SUB_COLLECTION_OF: + case ActionIdManager.SUB_COLLECTION_OF_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_SUB_COLLECTION_OF); + break; + case ActionIdManager.SUB_QUANTITY_OF: + case ActionIdManager.SUB_QUANTITY_OF_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_SUB_QUANTITY_OF); + break; + case ActionIdManager.BEGIN: + case ActionIdManager.BEGIN_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_BEGIN); + break; + case ActionIdManager.END: + case ActionIdManager.END_FIXED: + StereotypesManager.applyStereotype(element, StereotypesManager.STR_END); + break; + } + + boolean isSmartModelingEnabled = Configurations.getInstance().getProjectConfigurations() + .isSmartModellingEnabled(); + boolean isClass = element.getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS); + boolean isAssociation = element.getModelType().equals(IModelElementFactory.MODEL_TYPE_ASSOCIATION); + + if (isSmartModelingEnabled && isClass) + SmartModellingController.setClassMetaProperties((IClass) element); + + if (isSmartModelingEnabled && isAssociation) + SmartModellingController.setAssociationMetaProperties((IAssociation) element); + } + + private void defineActionBehavior(VPAction action, IModelElement element) { + + if (element.getModelType().equals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { + final IAssociation association = (IAssociation) element; + SmartModellingController.manageAssociationStereotypes(association, action); + return; + } + + if (element.getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS)) { + final IClass _class = (IClass) element; + SmartModellingController.manageClassStereotypes(_class, action); + return; + } + } + + private boolean isClassSelectionAllowed() { + + final DiagramManager dm = ApplicationManager.instance() + .getDiagramManager(); + IDiagramElement[] diagramElements = + dm.getActiveDiagram() != null ? + dm.getActiveDiagram().getSelectedDiagramElement() : + null ; + LinkedList superClasses = new LinkedList<>(); + + if (diagramElements == null) + return true; + + if (diagramElements.length == 1) + return true; + + //build list of Ids of all classes selected + for (IDiagramElement diagramElement : diagramElements) { + + ISimpleRelationship[] relationshipsTo = diagramElement.getModelElement().toToRelationshipArray(); + + for (int i = 0; relationshipsTo != null && i < relationshipsTo.length; i++) { + ISimpleRelationship relationshipTo = relationshipsTo[i]; + String superClassType = relationshipTo.getFrom() != null ? relationshipTo.getFrom().getModelType() : ""; + + if (!(superClassType.equals(IModelElementFactory.MODEL_TYPE_CLASS))) + continue; + + IClass superClass = (IClass) relationshipTo.getFrom(); + + superClasses.add(superClass.getId()); + } + } + + //Iterates over the list of the superclasses Id + //then iterate over the list again to count if the id + //was inserted the same amount as the amount of selected classes + int counter = 0; + + for (int i = 0; i < superClasses.size(); i++) { + String id = superClasses.get(i); + + for (int j = 0; j < superClasses.size(); j++) { + String idAux = superClasses.get(j); + + if (id.equals(idAux)) + counter++; + } + + if (counter == countClassesSelected()) + return true; + else + counter = 0; + } + + return false; + } + + private int countClassesSelected() { + + IDiagramElement[] diagramElements = ApplicationManager.instance().getDiagramManager().getActiveDiagram().getSelectedDiagramElement(); + int count = 0; + + if (diagramElements == null) + return count; + + for (IDiagramElement diagramElement : diagramElements) { + if (diagramElement.getModelElement().getModelType().equals(IModelElementFactory.MODEL_TYPE_CLASS)) + count++; + } + + return count++; + } + +} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationController.java similarity index 81% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationController.java index dd14de17..cb488cc2 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/DiagramVerificationController.java @@ -10,17 +10,16 @@ import com.vp.plugin.view.IDialog; import com.vp.plugin.view.IDialogHandler; -import it.unibz.inf.ontouml.vp.model.ModelElement; -import it.unibz.inf.ontouml.vp.utils.OntoUMLServerUtils; -import it.unibz.inf.ontouml.vp.utils.ServerRequest; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.model.ServerRequest; +import it.unibz.inf.ontouml.vp.model.uml.ModelElement; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; import it.unibz.inf.ontouml.vp.views.ProgressPanel; /** * Implementation of toolbar button action responsible for performing diagram verification. * */ -public class DiagramVerificationAction implements VPActionController { +public class DiagramVerificationController implements VPActionController { private ProgressPanel progressPanel; private ProgressDialog loading; @@ -39,7 +38,7 @@ public class DiagramVerificationAction implements VPActionController { public void performAction(VPAction action) { if (!hasOpenedClassDiagram()) { - ViewUtils.simpleDialog("Diagram Verification", "Please open a diagram before running this command."); + ViewManagerUtils.simpleDialog("Diagram Verification", "Please open a diagram before running this command."); return; } @@ -110,13 +109,13 @@ public class DiagramVerificationRequest extends ServerRequest { public void run() { while (keepRunning()) { try { - final String response = OntoUMLServerUtils.requestModelVerification(ModelElement.generateModel(true), loading); + final String response = OntoUMLServerAccessController.requestModelVerification(ModelElement.generateModel(true), loading); if (keepRunning()) { if (response != null) { mainDialog.close(); request.doStop(); - ViewUtils.logDiagramVerificationResponse(response); + ViewManagerUtils.logDiagramVerificationResponse(response); } else { loading.canClosed(); request.doStop(); @@ -124,7 +123,7 @@ public void run() { } else { loading.canClosed(); request.doStop(); - ViewUtils.cleanAndShowMessage("Request cancelled by the user."); + ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user."); } } catch (Exception e) { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ExportToGUFOAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GUFOExportController.java similarity index 87% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/ExportToGUFOAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/GUFOExportController.java index 37dde2c3..aeda99fc 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ExportToGUFOAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GUFOExportController.java @@ -16,13 +16,12 @@ import com.vp.plugin.view.IDialogHandler; import it.unibz.inf.ontouml.vp.OntoUMLPlugin; -import it.unibz.inf.ontouml.vp.model.ModelElement; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.OntoUMLServerUtils; -import it.unibz.inf.ontouml.vp.utils.ProjectConfigurations; -import it.unibz.inf.ontouml.vp.utils.ServerRequest; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; -import it.unibz.inf.ontouml.vp.views.ExportToGUFOView; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.ProjectConfigurations; +import it.unibz.inf.ontouml.vp.model.ServerRequest; +import it.unibz.inf.ontouml.vp.model.uml.ModelElement; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; +import it.unibz.inf.ontouml.vp.views.GUFOExportView; import it.unibz.inf.ontouml.vp.views.ProgressPanel; /** @@ -32,14 +31,14 @@ * @author Claudenir Fonseca * */ -public class ExportToGUFOAction implements VPActionController { +public class GUFOExportController implements VPActionController { private ProgressPanel progressPanel; private ProgressDialog loading; private IDialog mainDialog; private ExportDialog menu; - private ExportToGUFOView _exportMenuView; + private GUFOExportView _exportMenuView; private IDialog _dialog; MenuExport requestMenu; @@ -138,7 +137,7 @@ protected class ExportDialog implements IDialogHandler { */ @Override public Component getComponent() { - _exportMenuView = new ExportToGUFOView(Configurations.getInstance().getProjectConfigurations(), + _exportMenuView = new GUFOExportView(Configurations.getInstance().getProjectConfigurations(), requestMenu); return _exportMenuView; } @@ -179,7 +178,7 @@ public void shown() { public boolean canClosed() { requestMenu.doStop(); OntoUMLPlugin.setExportToGUFOWindowOpen(false); - ViewUtils.cleanAndShowMessage("Request cancelled by the user."); + ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user."); return true; } @@ -203,7 +202,7 @@ public void run() { loading = new ProgressDialog(); ApplicationManager.instance().getViewManager().showDialog(loading); - final BufferedReader gufo = OntoUMLServerUtils.transformToGUFO( + final BufferedReader gufo = OntoUMLServerAccessController.transformToGUFO( ModelElement.generateModel(_exportMenuView.getSavedElements(), true), projectConfigurations.getExportGUFOIRI(), projectConfigurations.getExportGUFOFormat(), @@ -217,18 +216,18 @@ public void run() { if (gufo != null) { saveFile(gufo,projectConfigurations.getExportGUFOFormat()); - ViewUtils.cleanAndShowMessage("Model exported successfully."); + ViewManagerUtils.cleanAndShowMessage("Model exported successfully."); requestMenu.doStop(); } else { menu.canClosed(); requestMenu.doStop(); - ViewUtils.cleanAndShowMessage( + ViewManagerUtils.cleanAndShowMessage( "Unable to transform to GUFO. Please check your model."); } } else { menu.canClosed(); requestMenu.doStop(); - ViewUtils.cleanAndShowMessage("Request cancelled by the user."); + ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user."); } OntoUMLPlugin.setExportToGUFOWindowOpen(false); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java new file mode 100644 index 00000000..8541f6b6 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/GitHubAccessController.java @@ -0,0 +1,86 @@ +package it.unibz.inf.ontouml.vp.controllers; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.channels.Channels; +import java.nio.channels.ReadableByteChannel; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +import javax.net.ssl.HttpsURLConnection; + +import com.google.gson.JsonArray; +import com.google.gson.JsonParser; + +import it.unibz.inf.ontouml.vp.OntoUMLPlugin; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.GitHubRelease; +import it.unibz.inf.ontouml.vp.model.GitHubReleaseAsset; + +public class GitHubAccessController { + + final public static String GITHUB_API = "https://api.github.com"; + final public static String REPOS = "/repos"; + final public static String RELEASES = "/releases"; + + public static void lookupUpdates() throws IOException { + List releases = GitHubAccessController.getReleases(); + Configurations config = Configurations.getInstance(); + config.setReleases(releases); + config.save(); + } + + public static List getReleases() throws IOException { + final URL url = new URL(GITHUB_API + REPOS + "/" + OntoUMLPlugin.PLUGIN_REPO_OWNER + "/" + + OntoUMLPlugin.PLUGIN_REPO_NAME + RELEASES); + final HttpsURLConnection request = (HttpsURLConnection) url.openConnection(); + + request.setRequestMethod("GET"); + request.setRequestProperty("Accept", "application/vnd.github.v3+json"); + request.setReadTimeout(60000); + + final int responseCode = request.getResponseCode(); + + if (responseCode == HttpsURLConnection.HTTP_OK) { + try (BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()))) { + StringBuilder response = new StringBuilder(); + String line; + + while ((line = in.readLine()) != null) { + response.append(line); + } + + JsonArray releasesArray = (JsonArray) new JsonParser().parse(response.toString()).getAsJsonArray(); + List releases = new ArrayList<>(); + + releasesArray.forEach(item -> { + releases.add(new GitHubRelease(item.getAsJsonObject())); + }); + + return releases; + } + } + + return null; + } + + public static File downloadReleaseAsset(GitHubReleaseAsset asset) throws MalformedURLException, IOException { + final URL downloadURL = new URL(asset.getDownloadUrl()); + final ReadableByteChannel rbc = Channels.newChannel(downloadURL.openStream()); + final Path pluginDownloadDir = Files.createTempDirectory("pluginDownloadDir"); + final File downloadFile = new File(pluginDownloadDir.toFile(), asset.getName()); + final FileOutputStream fos = new FileOutputStream(downloadFile); + + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + + return downloadFile; + } +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelExportAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonExportController.java similarity index 88% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelExportAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonExportController.java index 03cd00bc..cb41e49e 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelExportAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/JsonExportController.java @@ -5,10 +5,11 @@ import com.vp.plugin.action.VPActionController; import com.vp.plugin.view.IDialog; import com.vp.plugin.view.IDialogHandler; -import it.unibz.inf.ontouml.vp.model.ModelElement; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.ProjectConfigurations; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; + +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.ProjectConfigurations; +import it.unibz.inf.ontouml.vp.model.uml.ModelElement; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; import it.unibz.inf.ontouml.vp.views.ProgressPanel; import java.awt.*; @@ -22,7 +23,7 @@ * * @author Claudenir Fonseca */ -public class ModelExportAction implements VPActionController { +public class JsonExportController implements VPActionController { private ProgressPanel progressPanel; private ProgressDialog loading; @@ -73,9 +74,9 @@ public void performAction(VPAction action) { projectConfigurations.setExportFolderPath(fileDirectory); projectConfigurations.setExportFilename(fileName); configs.save(); - ViewUtils.cleanAndShowMessage("Model exported successfully."); + ViewManagerUtils.cleanAndShowMessage("Model exported successfully."); } catch (IOException e) { - ViewUtils.cleanAndShowMessage("Model export failed."); + ViewManagerUtils.cleanAndShowMessage("Model export failed."); e.printStackTrace(); } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java similarity index 81% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java index 07155fb4..760ac02e 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ModelVerificationController.java @@ -8,10 +8,9 @@ import com.vp.plugin.view.IDialog; import com.vp.plugin.view.IDialogHandler; -import it.unibz.inf.ontouml.vp.model.ModelElement; -import it.unibz.inf.ontouml.vp.utils.OntoUMLServerUtils; -import it.unibz.inf.ontouml.vp.utils.ServerRequest; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.model.ServerRequest; +import it.unibz.inf.ontouml.vp.model.uml.ModelElement; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; import it.unibz.inf.ontouml.vp.views.ProgressPanel; /** @@ -21,7 +20,7 @@ * @author Claudenir Fonseca * */ -public class ModelVerificationAction implements VPActionController { +public class ModelVerificationController implements VPActionController { private ProgressPanel progressPanel; private ProgressDialog loading; @@ -92,13 +91,13 @@ public class ModelVerificationRequest extends ServerRequest { public void run() { while (keepRunning()) { try { - final String response = OntoUMLServerUtils.requestModelVerification(ModelElement.generateModel(true), loading); + final String response = OntoUMLServerAccessController.requestModelVerification(ModelElement.generateModel(true), loading); if (keepRunning()) { if (response != null) { loading.canClosed(); request.doStop(); - ViewUtils.logVerificationResponse(response); + ViewManagerUtils.logVerificationResponse(response); } else { loading.canClosed(); request.doStop(); @@ -106,7 +105,7 @@ public void run() { } else { loading.canClosed(); request.doStop(); - ViewUtils.cleanAndShowMessage("Request cancelled by the user."); + ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user."); } } catch (Exception e) { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLServerUtils.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java similarity index 84% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLServerUtils.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java index 6cdc3fa9..f88eb03d 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLServerUtils.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/OntoUMLServerAccessController.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.utils; +package it.unibz.inf.ontouml.vp.controllers; import java.io.BufferedReader; import java.io.IOException; @@ -16,6 +16,10 @@ import com.google.gson.JsonParser; import com.vp.plugin.view.IDialogHandler; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.ProjectConfigurations; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; + /** * * Class responsible for making requests to the OntoUML Server based on standard @@ -25,7 +29,7 @@ * @author Victor Viola * */ -public class OntoUMLServerUtils { +public class OntoUMLServerAccessController { private static final String TRANSFORM_GUFO_SERVICE_ENDPOINT = "/v1/transform/gufo"; private static final String VERIFICATION_SERVICE_ENDPOINT = "/v1/verify"; @@ -87,7 +91,7 @@ public static BufferedReader transformToGUFO(String model, String baseIRI, Strin if (!request.getContentType().equals("text/html")) { return responseReader; } else { - if (ViewUtils.exportToGUFOIssueDialogWithOption("Server not found.", + if (ViewManagerUtils.exportToGUFOIssueDialogWithOption("Server not found.", HttpURLConnection.HTTP_NOT_FOUND)) return transformToGUFO(model, baseIRI, format, uriFormatBy, inverse, object, analysis, packages, elementMapping, packageMapping, loading); @@ -97,7 +101,7 @@ public static BufferedReader transformToGUFO(String model, String baseIRI, Strin return null; } case HttpURLConnection.HTTP_BAD_REQUEST: - ViewUtils.exportToGUFOIssueDialog("Unable to transform the model due to an unexpected error." + ViewManagerUtils.exportToGUFOIssueDialog("Unable to transform the model due to an unexpected error." + "\nPlease check the model for any syntactical errors." + "\n\nWarning: partially exporting models to gUFO may introduce syntactical errors."); System.out.println(responseReader.lines().collect(Collectors.joining())); @@ -106,7 +110,7 @@ public static BufferedReader transformToGUFO(String model, String baseIRI, Strin + "\n\nWarning: partially exporting models to gUFO may introduce syntactical errors.").printStackTrace(); return null; case HttpURLConnection.HTTP_NOT_FOUND: - if (ViewUtils.exportToGUFOIssueDialogWithOption("Server not found.", HttpURLConnection.HTTP_NOT_FOUND)) + if (ViewManagerUtils.exportToGUFOIssueDialogWithOption("Server not found.", HttpURLConnection.HTTP_NOT_FOUND)) return transformToGUFO(model, baseIRI, format, uriFormatBy, inverse, object, analysis, packages, elementMapping, packageMapping, loading); @@ -114,7 +118,7 @@ public static BufferedReader transformToGUFO(String model, String baseIRI, Strin new Exception("Server not found.").printStackTrace(); return null; case HttpURLConnection.HTTP_INTERNAL_ERROR: - if (ViewUtils.exportToGUFOIssueDialogWithOption("Server error.", HttpURLConnection.HTTP_INTERNAL_ERROR)) + if (ViewManagerUtils.exportToGUFOIssueDialogWithOption("Server error.", HttpURLConnection.HTTP_INTERNAL_ERROR)) return transformToGUFO(model, baseIRI, format, uriFormatBy, inverse, object, analysis, packages, elementMapping, packageMapping, loading); @@ -122,11 +126,11 @@ public static BufferedReader transformToGUFO(String model, String baseIRI, Strin new Exception("Server error.").printStackTrace(); return null; default: - ViewUtils.exportToGUFOIssueDialog("Unexpected error."); + ViewManagerUtils.exportToGUFOIssueDialog("Unexpected error."); throw new Exception("Unknown error"); } } catch (MalformedURLException e) { - ViewUtils.exportToGUFOIssueDialog("Server error."); + ViewManagerUtils.exportToGUFOIssueDialog("Server error."); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); @@ -170,41 +174,41 @@ public static String requestModelVerification(String serializedModel, IDialogHan if (!request.getContentType().equals("text/html")) { return response.toString(); } else { - if (ViewUtils.verificationFailedDialogWithOption(USER_MESSAGE_NOT_FOUND, + if (ViewManagerUtils.verificationFailedDialogWithOption(USER_MESSAGE_NOT_FOUND, HttpURLConnection.HTTP_NOT_FOUND)) return requestModelVerification(serializedModel, loading); } case HttpURLConnection.HTTP_BAD_REQUEST: - ViewUtils.verificationFailedDialog(USER_MESSAGE_BAD_REQUEST); + ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_BAD_REQUEST); return null; case HttpURLConnection.HTTP_NOT_FOUND: - if (ViewUtils.verificationFailedDialogWithOption(USER_MESSAGE_NOT_FOUND, + if (ViewManagerUtils.verificationFailedDialogWithOption(USER_MESSAGE_NOT_FOUND, HttpURLConnection.HTTP_NOT_FOUND)) return requestModelVerification(serializedModel, loading); return null; case HttpURLConnection.HTTP_INTERNAL_ERROR: - if (ViewUtils.verificationFailedDialogWithOption(USER_MESSAGE_INTERNAL_ERROR, + if (ViewManagerUtils.verificationFailedDialogWithOption(USER_MESSAGE_INTERNAL_ERROR, HttpURLConnection.HTTP_INTERNAL_ERROR)) return requestModelVerification(serializedModel, loading); return null; default: - ViewUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE); + ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE); return null; } } catch (SocketException e) { loading.canClosed(); - ViewUtils.verificationFailedDialog(USER_MESSAGE_NOT_FOUND); + ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_NOT_FOUND); e.printStackTrace(); } catch (IOException e) { loading.canClosed(); - ViewUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE); + ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_RESPONSE); e.printStackTrace(); } catch (Exception e) { loading.canClosed(); - ViewUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_REQUEST); + ViewManagerUtils.verificationFailedDialog(USER_MESSAGE_UNKNOWN_ERROR_REQUEST); e.printStackTrace(); } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/PaintModelAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/PaintModelAction.java deleted file mode 100644 index 6ed3c0b0..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/PaintModelAction.java +++ /dev/null @@ -1,37 +0,0 @@ -package it.unibz.inf.ontouml.vp.controllers; - -import javax.swing.JOptionPane; - -import com.vp.plugin.action.VPAction; -import com.vp.plugin.action.VPActionController; - -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.SmartColoring; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; - -public class PaintModelAction implements VPActionController { - - @Override - public void performAction(VPAction arg0) { - - if (!Configurations.getInstance().getProjectConfigurations().isAutomaticColoringEnabled()) { - final int enableSmartPaint = ViewUtils.smartPaintEnableDialog(); - - if (enableSmartPaint == JOptionPane.YES_OPTION) { - Configurations.getInstance().getProjectConfigurations().setAutomaticColoringEnabled(true); - SmartColoring.paintAll(); - } - } else { - final int proceedSmartPaintAction = ViewUtils.smartPaintConfirmationDialog(); - - if (proceedSmartPaintAction == JOptionPane.YES_OPTION) { - SmartColoring.paintAll(); - } - } - } - - @Override - public void update(VPAction arg0) { - } - -} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesActionController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesActionController.java deleted file mode 100644 index efe4ffef..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesActionController.java +++ /dev/null @@ -1,19 +0,0 @@ -package it.unibz.inf.ontouml.vp.controllers; - -import com.vp.plugin.action.VPAction; -import com.vp.plugin.action.VPActionController; - -import it.unibz.inf.ontouml.vp.OntoUMLPlugin; - -public class ReloadClassesActionController implements VPActionController { - - @Override - public void performAction(VPAction action) { - OntoUMLPlugin.reload(); - } - - @Override - public void update(VPAction action) { - } - -} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java new file mode 100644 index 00000000..08d571f3 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReloadClassesController.java @@ -0,0 +1,76 @@ +package it.unibz.inf.ontouml.vp.controllers; + +import java.util.Set; + +import com.vp.plugin.ApplicationManager; +import com.vp.plugin.DiagramManager; +import com.vp.plugin.action.VPAction; +import com.vp.plugin.action.VPActionController; +import com.vp.plugin.diagram.IDiagramUIModel; +import com.vp.plugin.model.IPackage; +import com.vp.plugin.model.factory.IModelElementFactory; + +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; + +public class ReloadClassesController implements VPActionController { + + @Override + public void performAction(VPAction action) { +// OntoUMLPlugin.reload(); +// generateModel(); + } + + @Override + public void update(VPAction action) { + } + + @SuppressWarnings("unused") + private void generateModel() { + final ApplicationManager app = ApplicationManager.instance(); + final DiagramManager dm = app.getDiagramManager(); + final IDiagramUIModel diagram = dm.getActiveDiagram(); + final IPackage pkg = (IPackage) diagram.getParentModel(); + final IModelElementFactory factory = IModelElementFactory.instance(); + + if(diagram == null || pkg == null) { return ; } + + final Set stereotypes = StereotypesManager.getOntoUMLClassStereotypeNames(); + + for (String sourceStereotype : stereotypes) { + final IPackage sourcePkg = factory.createPackage(); + sourcePkg.setName(sourceStereotype); + pkg.addChild(sourcePkg); + + for (String targetStereotype : stereotypes) { +// // Method getAllowedAssociations() was removed +// final List allowedAssociations = +// OntoUMLConstraintsManager.getAllowedAssociations(sourceStereotype, targetStereotype); + +// if(!allowedAssociations.isEmpty()) { +// final IClass source = factory.createClass(); +// final IClass target = factory.createClass(); +// +// source.setName(sourceStereotype + " as Source"); +// target.setName(targetStereotype + " as Target"); +// +// source.addStereotype(sourceStereotype); +// target.addStereotype(targetStereotype); +// +// sourcePkg.addChild(source); +// sourcePkg.addChild(target); +// +// for (String associationStereotype : allowedAssociations) { +// final IAssociation association = factory.createAssociation(); +// +// association.addStereotype(associationStereotype); +// association.setFrom(source); +// association.setTo(target); +// +// sourcePkg.addChild(association); +// } +// } + } + } + } + +} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java similarity index 73% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java index 089eadf5..f76d537f 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/ReportErrorController.java @@ -6,9 +6,9 @@ import com.vp.plugin.action.VPAction; import com.vp.plugin.action.VPActionController; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; -public class ReportErrorAction implements VPActionController { +public class ReportErrorController implements VPActionController { final private static String REPORT_URL = "https://forms.gle/btx7CDSy9kn5yb3WA"; @@ -19,13 +19,13 @@ public void performAction(VPAction arg0) { final URI uri = new URI(REPORT_URL); desktop.browse(uri); } catch (UnsupportedOperationException unsupportedException) { - ViewUtils.reportBugErrorDialog(true); + ViewManagerUtils.reportBugErrorDialog(true); unsupportedException.printStackTrace(); } catch (SecurityException securityException) { - ViewUtils.reportBugErrorDialog(true); + ViewManagerUtils.reportBugErrorDialog(true); securityException.printStackTrace(); } catch(Exception e) { - ViewUtils.reportBugErrorDialog(false); + ViewManagerUtils.reportBugErrorDialog(false); e.printStackTrace(); } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/OpenConfigurationsAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/SettingsMenuController.java similarity index 96% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/OpenConfigurationsAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/SettingsMenuController.java index 16f0873d..68f2ba2f 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/OpenConfigurationsAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/SettingsMenuController.java @@ -6,7 +6,7 @@ import com.vp.plugin.view.IDialog; import com.vp.plugin.view.IDialogHandler; import it.unibz.inf.ontouml.vp.OntoUMLPlugin; -import it.unibz.inf.ontouml.vp.utils.Configurations; +import it.unibz.inf.ontouml.vp.model.Configurations; import it.unibz.inf.ontouml.vp.views.ConfigurationsView; import java.awt.*; @@ -21,7 +21,7 @@ * @author Claudenir Fonseca * */ -public class OpenConfigurationsAction implements VPActionController { +public class SettingsMenuController implements VPActionController { private ConfigurationsView _configurationsMenuView; private IDialog _dialog; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/SmartModelling.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java similarity index 82% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/SmartModelling.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java index ced12cf9..d524900b 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/SmartModelling.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/SmartModellingController.java @@ -1,12 +1,8 @@ -package it.unibz.inf.ontouml.vp.utils; - -import it.unibz.inf.ontouml.vp.features.constraints.AssociationConstraints; -import it.unibz.inf.ontouml.vp.features.constraints.ClassConstraints; +package it.unibz.inf.ontouml.vp.controllers; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.AbstractMap.SimpleEntry; import com.vp.plugin.action.VPAction; import com.vp.plugin.model.IAssociation; @@ -16,7 +12,10 @@ import com.vp.plugin.model.ISimpleRelationship; import com.vp.plugin.model.factory.IModelElementFactory; -public class SmartModelling { +import it.unibz.inf.ontouml.vp.utils.OntoUMLConstraintsManager; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; + +public class SmartModellingController { public static void setAggregationKind(IModelElement element) { IAssociation association = (IAssociation) element; @@ -89,30 +88,30 @@ public static void setAssociationMetaProperties(IAssociation association) { return; switch (stereotypes[0]) { - case StereotypeUtils.STR_CHARACTERIZATION: + case StereotypesManager.STR_CHARACTERIZATION: setCardinalityIfEmpty(source, "1"); setCardinalityIfEmpty(target, "1"); target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_COMPARATIVE: + case StereotypesManager.STR_COMPARATIVE: setCardinalityIfEmpty(source, "0..*"); setCardinalityIfEmpty(target, "0..*"); association.setDerived(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_COMPONENT_OF: + case StereotypesManager.STR_COMPONENT_OF: setCardinalityIfEmpty(source, "1..*"); setCardinalityIfEmpty(target, "1"); setAggregationKind(association); return; - case StereotypeUtils.STR_MATERIAL: - if (targetStereotype.equals(StereotypeUtils.STR_ROLE) || targetStereotype.equals(StereotypeUtils.STR_ROLE_MIXIN)) + case StereotypesManager.STR_MATERIAL: + if (targetStereotype.equals(StereotypesManager.STR_ROLE) || targetStereotype.equals(StereotypesManager.STR_ROLE_MIXIN)) setCardinalityIfEmpty(source, "1..*"); else setCardinalityIfEmpty(source, "0..*"); - if (sourceStereotype.equals(StereotypeUtils.STR_ROLE) || sourceStereotype.equals(StereotypeUtils.STR_ROLE_MIXIN)) + if (sourceStereotype.equals(StereotypesManager.STR_ROLE) || sourceStereotype.equals(StereotypesManager.STR_ROLE_MIXIN)) setCardinalityIfEmpty(target, "1..*"); else setCardinalityIfEmpty(target, "0..*"); @@ -120,14 +119,14 @@ public static void setAssociationMetaProperties(IAssociation association) { association.setDerived(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_EXTERNAL_DEPENDENCE: + case StereotypesManager.STR_EXTERNAL_DEPENDENCE: setCardinalityIfEmpty(source, "0..*"); setCardinalityIfEmpty(target, "1..*"); target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_MEDIATION: - if (targetStereotype.equals(StereotypeUtils.STR_ROLE) || targetStereotype.equals(StereotypeUtils.STR_ROLE_MIXIN)) + case StereotypesManager.STR_MEDIATION: + if (targetStereotype.equals(StereotypesManager.STR_ROLE) || targetStereotype.equals(StereotypesManager.STR_ROLE_MIXIN)) setCardinalityIfEmpty(source, "1..*"); else setCardinalityIfEmpty(source, "0..*"); @@ -136,45 +135,45 @@ public static void setAssociationMetaProperties(IAssociation association) { target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_MEMBER_OF: + case StereotypesManager.STR_MEMBER_OF: setCardinalityIfEmpty(source, "1..*"); setCardinalityIfEmpty(target, "1..*"); setAggregationKind(association); return; - case StereotypeUtils.STR_SUB_COLLECTION_OF: + case StereotypesManager.STR_SUB_COLLECTION_OF: setCardinalityIfEmpty(source, "1"); setCardinalityIfEmpty(target, "1"); setAggregationKind(association); return; - case StereotypeUtils.STR_SUB_QUANTITY_OF: + case StereotypesManager.STR_SUB_QUANTITY_OF: setCardinalityIfEmpty(source, "1"); setCardinalityIfEmpty(target, "1"); source.setReadOnly(true); setAggregationKind(association); return; - case StereotypeUtils.STR_CREATION: + case StereotypesManager.STR_CREATION: setCardinalityIfEmpty(source, "1"); setCardinalityIfEmpty(target, "1"); source.setReadOnly(true); target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_HISTORICAL_DEPENDENCE: + case StereotypesManager.STR_HISTORICAL_DEPENDENCE: setCardinalityIfEmpty(source, "0..*"); setCardinalityIfEmpty(target, "1"); target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_MANIFESTATION: + case StereotypesManager.STR_MANIFESTATION: setCardinalityIfEmpty(source, "0..*"); setCardinalityIfEmpty(target, "1..*"); target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_PARTICIPATION: + case StereotypesManager.STR_PARTICIPATION: if ( - targetStereotype.equals(StereotypeUtils.STR_HISTORICAL_ROLE) || - targetStereotype.equals(StereotypeUtils.STR_HISTORICAL_ROLE_MIXIN) + targetStereotype.equals(StereotypesManager.STR_HISTORICAL_ROLE) || + targetStereotype.equals(StereotypesManager.STR_HISTORICAL_ROLE_MIXIN) ) setCardinalityIfEmpty(source, "1..*"); else @@ -184,21 +183,21 @@ public static void setAssociationMetaProperties(IAssociation association) { target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_PARTICIPATIONAL: + case StereotypesManager.STR_PARTICIPATIONAL: setCardinalityIfEmpty(source, "1..*"); setCardinalityIfEmpty(target, "1"); source.setReadOnly(true); target.setReadOnly(true); setAggregationKind(association); return; - case StereotypeUtils.STR_TERMINATION: + case StereotypesManager.STR_TERMINATION: setCardinalityIfEmpty(source, "1"); setCardinalityIfEmpty(target, "1"); source.setReadOnly(true); target.setReadOnly(true); removeAggregationKind(association); return; - case StereotypeUtils.STR_INSTANTIATION: + case StereotypesManager.STR_INSTANTIATION: setCardinalityIfEmpty(source, "0..*"); setCardinalityIfEmpty(target, "1..*"); source.setReadOnly(true); @@ -218,16 +217,16 @@ public static void setClassMetaProperties(IClass _class) { return; switch (stereotypes[0]) { - case StereotypeUtils.STR_CATEGORY: + case StereotypesManager.STR_CATEGORY: _class.setAbstract(true); break; - case StereotypeUtils.STR_ROLE_MIXIN: + case StereotypesManager.STR_ROLE_MIXIN: _class.setAbstract(true); break; - case StereotypeUtils.STR_PHASE_MIXIN: + case StereotypesManager.STR_PHASE_MIXIN: _class.setAbstract(true); break; - case StereotypeUtils.STR_MIXIN: + case StereotypesManager.STR_MIXIN: _class.setAbstract(true); break; } @@ -257,7 +256,7 @@ public static void manageAssociationStereotypes(IAssociation association, VPActi final String sourceStereotype = sourceStereotypes.get(0); final String targetStereotype = targetStereotypes.get(0); // final ArrayList allowedCombinations = AssociationConstraints.allowedCombinations.get(new SimpleEntry(sourceStereotype, targetStereotype)); - final List allowedCombinations = AssociationConstraints.getAllowedActionIDs(sourceStereotype, targetStereotype); + final List allowedCombinations = OntoUMLConstraintsManager.getAllowedStereotypeActionsOnAssociation(sourceStereotype, targetStereotype); if (allowedCombinations == null || !allowedCombinations.contains(action.getActionId())) action.setEnabled(false); @@ -288,7 +287,7 @@ public static void manageClassStereotypes(IClass _class, VPAction action) { action.setEnabled(false); final String superStereotype = superClassStereotypes.get(0); - final List allowedCombinationsSub = ClassConstraints.getAllowedActionIDsOnGeneral(superStereotype); + final List allowedCombinationsSub = OntoUMLConstraintsManager.getAllowedStereotypeActionsOnGeneral(superStereotype); if (allowedCombinationsSub == null || !allowedCombinationsSub.contains(action.getActionId())) action.setEnabled(false); @@ -312,7 +311,7 @@ public static void manageClassStereotypes(IClass _class, VPAction action) { action.setEnabled(false); final String subStereotype = subClassStereotypes.get(0); - final List allowedCombinationsSuper = ClassConstraints.getAllowedActionIDsOnSpecific(subStereotype); + final List allowedCombinationsSuper = OntoUMLConstraintsManager.getAllowedStereotypeActionsSpecific(subStereotype); if (allowedCombinationsSuper == null || !allowedCombinationsSuper.contains(action.getActionId())) action.setEnabled(false); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginAction.java b/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java similarity index 51% rename from src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginAction.java rename to src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java index e8d8b5b0..63db85ce 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginAction.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/controllers/UpdatePluginController.java @@ -1,7 +1,5 @@ package it.unibz.inf.ontouml.vp.controllers; -import java.awt.FileDialog; -import java.awt.Frame; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -12,47 +10,44 @@ import java.util.zip.ZipInputStream; import com.vp.plugin.ApplicationManager; -import com.vp.plugin.VPPluginInfo; import com.vp.plugin.action.VPAction; import com.vp.plugin.action.VPActionController; import it.unibz.inf.ontouml.vp.OntoUMLPlugin; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; -//import net.lingala.zip4j.core.ZipFile; -//import net.lingala.zip4j.exception.ZipException; +import it.unibz.inf.ontouml.vp.model.GitHubRelease; +import it.unibz.inf.ontouml.vp.model.GitHubReleaseAsset; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; -public class UpdatePluginAction implements VPActionController { +public class UpdatePluginController implements VPActionController { private static final int BUFFER_SIZE = 4096; @Override public void performAction(VPAction arg0) { - ViewUtils.updateDialog(); - - FileDialog fd = new FileDialog((Frame) ApplicationManager.instance().getViewManager().getRootFrame(), - "Select the zip file containing the OntoUML Plugin release", FileDialog.LOAD); - - fd.setDirectory(null); - fd.setFile(null); - fd.setFilenameFilter((dir, name) -> name != null && name.endsWith(".zip")); - fd.setVisible(true); - - if (fd.getDirectory() != null && fd.getFile() != null) { - final String fileName = fd.getFile(); - final VPPluginInfo info = ApplicationManager.instance().getPluginInfo(OntoUMLPlugin.PLUGIN_ID); - final File pluginsDir = info.getPluginDir().getParentFile(); - final File zipFile = new File(fd.getDirectory(), fileName); - final String destDirName = fileName.substring(0, fileName.lastIndexOf(".zip")); - try { - unzip(zipFile, pluginsDir.getAbsolutePath() + File.separator + destDirName); - deleteFolderContents(pluginsDir, - content -> content.isDirectory() && content.getName().contains("ontouml") - && !content.getName().equals("ontouml-vp-plugin-0.3.0-SNAPSHOT")); - ViewUtils.updateSuccessDialog(); - } catch (Exception e) { - ViewUtils.updateErrorDialog(); - e.printStackTrace(); + + try { + GitHubAccessController.lookupUpdates(); + GitHubRelease selectedRelease = ViewManagerUtils.updateDialog(); + GitHubReleaseAsset pluginAsset = selectedRelease != null ? selectedRelease.getInstallationFileAsset() : null; + + if (selectedRelease == null || pluginAsset == null) { + return; } + + File downloadedFile = GitHubAccessController.downloadReleaseAsset(pluginAsset); + + String destinationDirName = pluginAsset.getName().replace(".zip", ""); + File pluginDir = ApplicationManager.instance().getPluginInfo(OntoUMLPlugin.PLUGIN_ID).getPluginDir(); + File destinationDir = new File(pluginDir.getParentFile(), destinationDirName); + + UpdatePluginController.unzip(downloadedFile, destinationDir); + deleteFolderContents(pluginDir.getParentFile(), + content -> content.isDirectory() && content.getName().contains("ontouml-vp-plugin") + && !content.getName().equals(destinationDirName)); + ViewManagerUtils.updateSuccessDialog(); + } catch (Exception e) { + ViewManagerUtils.updateErrorDialog(); + e.printStackTrace(); } } @@ -60,10 +55,9 @@ public void performAction(VPAction arg0) { public void update(VPAction arg0) { } - public void unzip(File zipFile, String destDirectory) throws IOException { - File destDir = new File(destDirectory); - if (!destDir.exists()) { - destDir.mkdir(); + private static void unzip(File zipFile, File destDirectory) throws IOException { + if (!destDirectory.exists()) { + destDirectory.mkdir(); } ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry entry = zipIn.getNextEntry(); @@ -84,8 +78,10 @@ public void unzip(File zipFile, String destDirectory) throws IOException { zipIn.close(); } - private void extractFile(ZipInputStream zipIn, String filePath) throws IOException { - BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); + private static void extractFile(ZipInputStream zipIn, String filePath) throws IOException { + File file = new File(filePath); + file.createNewFile(); + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); byte[] bytesIn = new byte[BUFFER_SIZE]; int read = 0; while ((read = zipIn.read(bytesIn)) != -1) { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/AssociationConstraints.java b/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/AssociationConstraints.java deleted file mode 100644 index 8eb7ed24..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/AssociationConstraints.java +++ /dev/null @@ -1,84 +0,0 @@ -package it.unibz.inf.ontouml.vp.features.constraints; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; -import com.vp.plugin.ApplicationManager; -import com.vp.plugin.VPPluginInfo; - -import it.unibz.inf.ontouml.vp.OntoUMLPlugin; - -public class AssociationConstraints { - - final private static Type mapOfListsType = new TypeToken>>() { - }.getType(); - private static String filename = "association_constraints.json"; - private static String filepath; - - private static Map> constraints; - - private static void loadConstraints() { - try { - if(filepath == null) { - final ApplicationManager app = ApplicationManager.instance(); - final VPPluginInfo[] plugins = app.getPluginInfos(); - - for (VPPluginInfo plugin : plugins) { - if(plugin.getPluginId().equals(OntoUMLPlugin.PLUGIN_ID)) { - File pluginDir = plugin.getPluginDir(); - filepath = pluginDir.getAbsolutePath() + File.separator + filename; - } - } - } - - final JsonParser parser = new JsonParser(); - final JsonElement element = parser.parse(new FileReader(filepath)); - final Gson gson = new Gson(); - constraints = gson.fromJson(element, mapOfListsType); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - public static List getAllowedActionIDs(String sourceStereotype, String targetStereotype) { - if(constraints == null) { - loadConstraints(); - } - - List allowedStereotypes = constraints.get(sourceStereotype + ":" + targetStereotype); - - if(allowedStereotypes == null) { - allowedStereotypes = new ArrayList(); - } - - return allowedStereotypes - .stream() - .map(allowed -> ActionIds.associationStereotypeToActionID(allowed)) - .collect(Collectors.toList()); - } - - public static List getAllowedAssociations(String sourceStereotype, String targetStereotype) { - if(constraints == null) { - loadConstraints(); - } - - List allowedStereotypes = constraints.get(sourceStereotype + ":" + targetStereotype); - - if(allowedStereotypes == null) { - allowedStereotypes = new ArrayList(); - } - - return allowedStereotypes; - } - -} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ClassConstraints.java b/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ClassConstraints.java deleted file mode 100644 index 5039966d..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ClassConstraints.java +++ /dev/null @@ -1,92 +0,0 @@ -package it.unibz.inf.ontouml.vp.features.constraints; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import com.google.gson.Gson; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; -import com.vp.plugin.ApplicationManager; -import com.vp.plugin.VPPluginInfo; - -import it.unibz.inf.ontouml.vp.OntoUMLPlugin; - -public class ClassConstraints { - - final private static Type mapOfListsType = new TypeToken>>() { - }.getType(); - private static String filename = "generalization_constraints.json"; - private static String filepath; - - private static JsonObject constraints; - private static Map> allowedSuperClassesFor, allowedSubClassesFor; - - private static void loadConstraints() { - try { - if(filepath == null) { - final ApplicationManager app = ApplicationManager.instance(); - final VPPluginInfo[] plugins = app.getPluginInfos(); - - for (VPPluginInfo plugin : plugins) { - if(plugin.getPluginId().equals(OntoUMLPlugin.PLUGIN_ID)) { - File pluginDir = plugin.getPluginDir(); - filepath = pluginDir.getAbsolutePath() + File.separator + filename; - } - } - } - - final JsonParser parser = new JsonParser(); - final JsonElement element = parser.parse(new FileReader(filepath)); - constraints = element.getAsJsonObject(); - - final Gson gson = new Gson(); - allowedSubClassesFor = gson.fromJson(constraints.getAsJsonObject("allowedSubClassesFor"), mapOfListsType); - allowedSuperClassesFor = gson.fromJson(constraints.getAsJsonObject("allowedSuperClassesFor"), mapOfListsType); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - - public static List getAllowedActionIDsOnGeneral(String stereotype) { - if(constraints == null) { - loadConstraints(); - } - - List allowedStereotypes = allowedSubClassesFor.get(stereotype); - - if(allowedStereotypes == null) { - allowedStereotypes = new ArrayList(); - } - - return allowedStereotypes - .stream() - .map(allowed -> ActionIds.classStereotypeToActionID(allowed)) - .collect(Collectors.toList()); - } - - public static List getAllowedActionIDsOnSpecific(String stereotype) { - if(constraints == null) { - loadConstraints(); - } - - List allowedStereotypes = allowedSuperClassesFor.get(stereotype); - - if(allowedStereotypes == null) { - allowedStereotypes = new ArrayList(); - } - - return allowedStereotypes - .stream() - .map(allowed -> ActionIds.classStereotypeToActionID(allowed)) - .collect(Collectors.toList()); - } - -} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java b/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java index 3a471184..621f0f80 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/listeners/DiagramListener.java @@ -7,8 +7,8 @@ import com.vp.plugin.diagram.IDiagramUIModel; import com.vp.plugin.diagram.shape.IClassUIModel; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.SmartColoring; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.utils.SmartColoringUtils; public class DiagramListener implements IDiagramListener { @@ -50,7 +50,7 @@ private void smartPaint(IDiagramElement diagramElement) { diagramElement instanceof IClassUIModel && Configurations.getInstance().getProjectConfigurations().isAutomaticColoringEnabled() ) { - SmartColoring.paint((IClassUIModel) diagramElement); + SmartColoringUtils.paint((IClassUIModel) diagramElement); } } @@ -64,7 +64,7 @@ private void smartPaint(IDiagramUIModel diagram) { final IDiagramElement next = (IDiagramElement) iter.next(); if(next instanceof IClassUIModel) { - SmartColoring.paint((IClassUIModel) next); + SmartColoringUtils.paint((IClassUIModel) next); } } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java b/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java new file mode 100644 index 00000000..b5bd2b30 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/listeners/IssueLogMenuListener.java @@ -0,0 +1,55 @@ +package it.unibz.inf.ontouml.vp.listeners; + +import javax.swing.*; + +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; +import it.unibz.inf.ontouml.vp.views.IssueLogMenu; + +import java.awt.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; + +public final class IssueLogMenuListener extends MouseAdapter { + private ArrayList idModelElementList; + private JList messageList; + + public IssueLogMenuListener(ArrayList list, JList messages) { + super(); + idModelElementList = list; + messageList = messages; + } + + @Override + public void mouseMoved(MouseEvent e) { + final Point p = e.getPoint(); + final int index = messageList.locationToIndex(p); + + messageList.setSelectedIndex(index); + } + + @Override + public void mouseExited(MouseEvent e) { + messageList.clearSelection(); + } + + public void mouseReleased(MouseEvent e) { + doPop(e); + } + + private void doPop(MouseEvent e) { + IssueLogMenu menu; + String idModelElement = idModelElementList.get(messageList.locationToIndex(e.getPoint())); + + if (idModelElement == null) { + menu = new IssueLogMenu(); + } else { + menu = new IssueLogMenu(idModelElement); + if (!ViewManagerUtils.isElementInAnyDiagram(idModelElement)) { + menu.disableItem("Take me there!"); + } + } + + menu.show(e.getComponent(), e.getX(), e.getY()); + } +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/listeners/ModelListener.java b/src/main/java/it/unibz/inf/ontouml/vp/listeners/ModelListener.java index f0c75a3d..8c249b9d 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/listeners/ModelListener.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/listeners/ModelListener.java @@ -7,11 +7,11 @@ import com.vp.plugin.model.IClass; import com.vp.plugin.model.IGeneralization; -import it.unibz.inf.ontouml.vp.model.Class; -import it.unibz.inf.ontouml.vp.model.Generalization; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.SmartColoring; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.uml.Class; +import it.unibz.inf.ontouml.vp.model.uml.Generalization; +import it.unibz.inf.ontouml.vp.utils.SmartColoringUtils; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; public class ModelListener implements PropertyChangeListener { @@ -19,7 +19,7 @@ public class ModelListener implements PropertyChangeListener { final public static String PCN_MODEL_VIEW_ADDED = "modelViewAdded"; // Events on classes final public static String PCN_STEREOTYPES = "stereotypes"; - final public static String PCN_RESTRICTED_TO = StereotypeUtils.PROPERTY_RESTRICTED_TO; + final public static String PCN_RESTRICTED_TO = StereotypesManager.PROPERTY_RESTRICTED_TO; final public static String PCN_FROM_RELATIONSHIP_ADDED = "fromRelationshipAdded"; final public static String PCN_FROM_RELATIONSHIP_REMOVED = "fromRelationshipRemoved"; final public static String PCN_TO_RELATIONSHIP_ADDED = "toRelationshipAdded"; @@ -31,9 +31,9 @@ public class ModelListener implements PropertyChangeListener { final private Set interestStereotypes; public ModelListener() { - interestStereotypes = StereotypeUtils.getSortalStereotypeNames(); - interestStereotypes.addAll(StereotypeUtils.getUltimateSortalStereotypeNames()); - interestStereotypes.add(StereotypeUtils.STR_TYPE); + interestStereotypes = StereotypesManager.getSortalStereotypeNames(); + interestStereotypes.addAll(StereotypesManager.getUltimateSortalStereotypeNames()); + interestStereotypes.add(StereotypesManager.STR_TYPE); } @Override @@ -109,13 +109,13 @@ private void smartPaint(PropertyChangeEvent event) { final Object oldRestriction = event.getOldValue(); if (_class != null && !newRestriction.equals(oldRestriction)) { - SmartColoring.paint(_class); + SmartColoringUtils.paint(_class); } } private void enforceAndPropagateRestrictedTo(PropertyChangeEvent event) { final IClass _class = event.getSource() instanceof IClass ? (IClass) event.getSource() : null; - final String stereotype = StereotypeUtils.getUniqueStereotypeName(_class); + final String stereotype = StereotypesManager.getUniqueStereotypeName(_class); final Object newValue = event.getNewValue(); final Object oldValue = event.getOldValue(); @@ -124,34 +124,34 @@ private void enforceAndPropagateRestrictedTo(PropertyChangeEvent event) { } switch (stereotype) { - case StereotypeUtils.STR_EVENT: - case StereotypeUtils.STR_DATATYPE: - case StereotypeUtils.STR_ENUMERATION: - case StereotypeUtils.STR_KIND: - case StereotypeUtils.STR_COLLECTIVE: - case StereotypeUtils.STR_QUANTITY: - case StereotypeUtils.STR_RELATOR: - case StereotypeUtils.STR_MODE: - case StereotypeUtils.STR_QUALITY: - case StereotypeUtils.STR_TYPE: + case StereotypesManager.STR_EVENT: + case StereotypesManager.STR_DATATYPE: + case StereotypesManager.STR_ENUMERATION: + case StereotypesManager.STR_KIND: + case StereotypesManager.STR_COLLECTIVE: + case StereotypesManager.STR_QUANTITY: + case StereotypesManager.STR_RELATOR: + case StereotypesManager.STR_MODE: + case StereotypesManager.STR_QUALITY: + case StereotypesManager.STR_TYPE: if (!newValue.equals(oldValue)) { Class.setDefaultRestrictedTo(_class); propagateRestrictionsToDescendants(_class); } break; - case StereotypeUtils.STR_CATEGORY: - case StereotypeUtils.STR_ROLE_MIXIN: - case StereotypeUtils.STR_PHASE_MIXIN: - case StereotypeUtils.STR_MIXIN: - case StereotypeUtils.STR_HISTORICAL_ROLE_MIXIN: + case StereotypesManager.STR_CATEGORY: + case StereotypesManager.STR_ROLE_MIXIN: + case StereotypesManager.STR_PHASE_MIXIN: + case StereotypesManager.STR_MIXIN: + case StereotypesManager.STR_HISTORICAL_ROLE_MIXIN: if (!newValue.equals(oldValue)) { propagateRestrictionsToDescendants(_class); } break; - case StereotypeUtils.STR_SUBKIND: - case StereotypeUtils.STR_ROLE: - case StereotypeUtils.STR_PHASE: - case StereotypeUtils.STR_HISTORICAL_ROLE: + case StereotypesManager.STR_SUBKIND: + case StereotypesManager.STR_ROLE: + case StereotypesManager.STR_PHASE: + case StereotypesManager.STR_HISTORICAL_ROLE: final Set sortalParents = getSortalParents(_class); final String parentsRestrictions = Class.getRestrictedTo(sortalParents); String currentRestrictions = Class.getRestrictedTo(_class); @@ -168,17 +168,17 @@ private void enforceAndPropagateRestrictedTo(PropertyChangeEvent event) { private void lookupAndPropagateRestrictedTo(Object classObject) { final IClass _class = classObject instanceof IClass ? (IClass) classObject : null; - final String stereotype = _class != null ? StereotypeUtils.getUniqueStereotypeName(_class) : null; + final String stereotype = _class != null ? StereotypesManager.getUniqueStereotypeName(_class) : null; if (_class == null || stereotype == null) { return; } switch (stereotype) { - case StereotypeUtils.STR_SUBKIND: - case StereotypeUtils.STR_ROLE: - case StereotypeUtils.STR_PHASE: - case StereotypeUtils.STR_HISTORICAL_ROLE: + case StereotypesManager.STR_SUBKIND: + case StereotypesManager.STR_ROLE: + case StereotypesManager.STR_PHASE: + case StereotypesManager.STR_HISTORICAL_ROLE: final Set interestParents = getSortalParents(_class); final String parentsRestrictions = Class.getRestrictedTo(interestParents); @@ -195,7 +195,7 @@ private void lookupAndPropagateRestrictedTo(Object classObject) { private void propagateRestrictionsToDescendants(IClass _class) { Class.applyOnDescendants(_class, descendent -> { - String descendentStereotype = StereotypeUtils.getUniqueStereotypeName(descendent); + String descendentStereotype = StereotypesManager.getUniqueStereotypeName(descendent); if (!interestStereotypes.contains(descendentStereotype)) { return false; @@ -219,7 +219,7 @@ private void propagateRestrictionsToDescendants(IClass _class) { private Set getSortalParents(IClass _class) { final Set sortalParents = Class.getParents(_class); sortalParents.removeIf(parent -> { - final String parentStereotype = StereotypeUtils.getUniqueStereotypeName(parent); + final String parentStereotype = StereotypesManager.getUniqueStereotypeName(parent); return !interestStereotypes.contains(parentStereotype); }); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/listeners/ProjectListener.java b/src/main/java/it/unibz/inf/ontouml/vp/listeners/ProjectListener.java index 348bf0aa..5d01bed1 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/listeners/ProjectListener.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/listeners/ProjectListener.java @@ -1,10 +1,18 @@ package it.unibz.inf.ontouml.vp.listeners; +import java.time.ZonedDateTime; +import java.util.List; + import com.vp.plugin.ApplicationManager; import com.vp.plugin.model.IProject; import com.vp.plugin.model.IProjectListener; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; +import it.unibz.inf.ontouml.vp.OntoUMLPlugin; +import it.unibz.inf.ontouml.vp.controllers.GitHubAccessController; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.GitHubRelease; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; public class ProjectListener implements IProjectListener { @@ -15,7 +23,7 @@ public ProjectListener() { projectModelListener = new ProjectModelListener(); projectDiagramListener = new ProjectDiagramListener(); addListeners(); - StereotypeUtils.generate(); + StereotypesManager.generate(); } private void addListeners() { @@ -33,6 +41,45 @@ private void addListeners() { e.printStackTrace(); } } + + private void checkUpdates() { + try { + Configurations config = Configurations.getInstance(); + ZonedDateTime lastCheck = config.getLastUpdatesCheck(); + + if(lastCheck != null && lastCheck.plusDays(1).isBefore(ZonedDateTime.now())) { + GitHubAccessController.lookupUpdates(); + List releases = config.getReleases(); + GitHubRelease latestRelease = config.getLatestRelease(); + boolean upToDate = false; + + for (GitHubRelease release : releases) { + if( + release.getTagName().equals(OntoUMLPlugin.PLUGIN_VERSION_RELEASE) + && release.getCreatedAt().isBefore(latestRelease.getCreatedAt()) + ) { + upToDate = true; + } + } + + if(!upToDate) { + System.out.println("New updates are available."); + ViewManagerUtils.simpleLog("New updates are available. Go to \"Update Plugin\" to get the latest version of the OntoUML Plugin for Visual Paradigm."); + } else { + System.out.println("No new updates available."); + ViewManagerUtils.simpleLog("Your OntoUML Plugin for Visual Paradigm is up to date with our latest release."); + } + } else { + System.out.println("Last check for updates was already performed in the last 24 hours."); + } + + config.setLastUpdatesCheck(ZonedDateTime.now()); + + } catch (Exception e) { + System.out.println("Failed to get releases from GitHub"); + e.printStackTrace(); + } + } @Override public void projectAfterOpened(IProject project) { @@ -57,7 +104,9 @@ public void projectNewed(IProject project) { } @Override - public void projectOpened(IProject project) {} + public void projectOpened(IProject project) { + checkUpdates(); + } @Override public void projectPreSave(IProject project) {} @@ -66,6 +115,8 @@ public void projectPreSave(IProject project) {} public void projectRenamed(IProject project) {} @Override - public void projectSaved(IProject project) {} + public void projectSaved(IProject project) { + checkUpdates(); + } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Configurations.java b/src/main/java/it/unibz/inf/ontouml/vp/model/Configurations.java new file mode 100644 index 00000000..073835da --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/Configurations.java @@ -0,0 +1,244 @@ +package it.unibz.inf.ontouml.vp.model; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSyntaxException; +import com.google.gson.annotations.Expose; +import com.vp.plugin.ApplicationManager; +import com.vp.plugin.model.IProject; + +import it.unibz.inf.ontouml.vp.OntoUMLPlugin; + +/** + * + * OntoUML Plugin configuration utility, allows persisting user preferences on + * the functionalities enabled by the plugin. + * + * @author Claudenir Fonseca + * + */ +public class Configurations { + + private static final String CONFIG_FILE_NAME = ".ontouml.config.json"; + + private static Configurations instance; + + @Expose() + private List projects; + + @Expose() + private List releases; + + @Expose() + private GitHubRelease latestRelease; + + @Expose() + private GitHubRelease latestAlphaRelease; + + @Expose() + private GitHubRelease installedRelease; + + // Since Gson shows problems with the default serialization of ZonedDateTime we rely on strings + @Expose() + private String lastUpdatesCheck; + + private Configurations() { + this.projects = new ArrayList(); + this.releases = new ArrayList<>(); + this.latestRelease = null; + this.latestAlphaRelease = null; + this.installedRelease = null; + this.lastUpdatesCheck = ZonedDateTime.now().toString(); + } + + private List getProjectConfigurationsList() { + return projects; + } + + private boolean addProjectConfigurations(ProjectConfigurations projectConfigurations) { + return getProjectConfigurationsList().add(projectConfigurations); + } + + public List getReleases() { + return releases; + } + + public void setReleases(List releases) { + if (releases == null) { + return; + } + + this.releases = releases; + + this.releases.forEach(release -> { + if (release.isPrerelease()) { + latestAlphaRelease = latestAlphaRelease == null + || latestAlphaRelease.getCreatedAt() == null + || release.getCreatedAt().isAfter(latestAlphaRelease.getCreatedAt()) + ? release : latestAlphaRelease; + } else { + latestRelease = latestRelease == null + || latestRelease.getCreatedAt() == null + || release.getCreatedAt().isAfter(latestRelease.getCreatedAt()) + ? release : latestRelease; + } + + installedRelease = release.getTagName().equals(OntoUMLPlugin.PLUGIN_VERSION_RELEASE) + ? release : installedRelease; + }); + } + + public ZonedDateTime getLastUpdatesCheck() { + return ZonedDateTime.parse(lastUpdatesCheck); + } + + public void setLastUpdatesCheck(ZonedDateTime lastUpdatesCheck) { + this.lastUpdatesCheck = lastUpdatesCheck.toString(); + } + + public GitHubRelease getLatestRelease() { + return latestRelease; + } + + public GitHubRelease getLatestAlphaRelease() { + return latestAlphaRelease; + } + + public GitHubRelease getInstalledRelease() { + return installedRelease; + } + + /** + * + * Returns singleton instance of the class. + * + * @return configurations + * + */ + public static Configurations getInstance() { + if (instance == null) { + final ApplicationManager application = ApplicationManager.instance(); + final File workspace = application.getWorkspaceLocation(); + final File configurationsFile = new File(workspace, CONFIG_FILE_NAME); + + if (configurationsFile.exists()) { + String json = ""; + try { + json = new String(Files.readAllBytes(configurationsFile.toPath())); + Gson gson = new Gson(); + instance = gson.fromJson(json, Configurations.class); + } catch (Exception e) { + if (e instanceof IOException) + application.getViewManager().showMessage( + "Unable to load configuration file (" + OntoUMLPlugin.PLUGIN_NAME + ").\n"); + else if (e instanceof JsonSyntaxException) + application.getViewManager() + .showMessage("Configuration file ill-formed (" + OntoUMLPlugin.PLUGIN_NAME + ").\n"); + else + application.getViewManager().showMessage("Unknown error while reading configuration file (" + + OntoUMLPlugin.PLUGIN_NAME + ").\n"); + + e.printStackTrace(); + } + } + + if (instance == null) + instance = new Configurations(); + } + + return instance; + } + + /** + * + * Persists user preferences on Visual Paradigm's workspace. + * + */ + public void save() { + final ApplicationManager application = ApplicationManager.instance(); + final File workspace = application.getWorkspaceLocation(); + final File configurationsFile = new File(workspace, CONFIG_FILE_NAME); + final FileWriter fw; + final GsonBuilder builder = new GsonBuilder(); + + builder.registerTypeAdapter(ZonedDateTime.class, new JsonDeserializer() { + + @Override + public ZonedDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + return ZonedDateTime.parse(json.getAsJsonPrimitive().getAsString()); + } + }); + + builder.setPrettyPrinting(); +// builder.excludeFieldsWithoutExposeAnnotation(); + + final Gson gson = builder.create(); + final String json = gson.toJson(this); + + try { + if (!configurationsFile.exists()) { + configurationsFile.createNewFile(); + } + + fw = new FileWriter(configurationsFile); + fw.write(json); + fw.close(); + } catch (IOException e) { + application.getViewManager().showMessage("Unable save " + OntoUMLPlugin.PLUGIN_NAME + " configurations."); + e.printStackTrace(); + } + } + + /** + * + * Retrieves the configurations of the current project. + * + * @return current project's configurations. + * + */ + public ProjectConfigurations getProjectConfigurations() { + final IProject current = ApplicationManager.instance().getProjectManager().getProject(); + + return getProjectConfigurations(current.getId()); + } + + /** + * + * Retrieves the project configurations given the provided ID. If no previous + * configurations is present, a new instance of + * ProjectConfigurations is returned with default settings. + * + * @param projectId - Interest project's ID. + * + * @return current project's configurations. + * + * + */ + public ProjectConfigurations getProjectConfigurations(String projectId) { + for (ProjectConfigurations projectConfigurations : getProjectConfigurationsList()) { + if (projectConfigurations.getId().equals(projectId)) { + return projectConfigurations; + } + } + + ProjectConfigurations projectConfigurations = new ProjectConfigurations(projectId); + addProjectConfigurations(projectConfigurations); + + return projectConfigurations; + } + +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/GitHubRelease.java b/src/main/java/it/unibz/inf/ontouml/vp/model/GitHubRelease.java new file mode 100644 index 00000000..3f74b8d8 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/GitHubRelease.java @@ -0,0 +1,108 @@ +package it.unibz.inf.ontouml.vp.model; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class GitHubRelease { + + final private static String PROP_TAG_NAME = "tag_name"; + final private static String PROP_CREATED_AT = "created_at"; + final private static String PROP_PRERELEASE = "prerelease"; + final private static String PROP_ASSETS = "assets"; + final private static String PROP_ID = "id"; + + @Expose() + private String tagName; + + // Since Gson shows problems with the default serialization of ZonedDateTime we rely on strings + @Expose() + private String createdAt; + + @Expose() + private boolean isPrerelease; + + @Expose() + private List assets; + + @Expose() + private GitHubReleaseAsset installationFileAsset; + + @SerializedName("releaseId") + @Expose() + private String id; + + public GitHubRelease() { + tagName = null; + createdAt = null; + isPrerelease = false; + assets = null; + installationFileAsset = null; + id = null; + } + + public GitHubRelease(JsonObject source) { + if (source == null) { + throw new NullPointerException(); + } + + tagName = source.get(PROP_TAG_NAME).getAsString(); + createdAt = source.get(PROP_CREATED_AT).getAsString(); + isPrerelease = source.get(PROP_PRERELEASE).getAsBoolean(); + id = source.get(PROP_ID).getAsString(); + + assets = new ArrayList<>(); + installationFileAsset = null; + + JsonArray assetsArray = source.get(PROP_ASSETS).getAsJsonArray(); + assetsArray.forEach(item -> { + GitHubReleaseAsset asset = item.isJsonObject() ? new GitHubReleaseAsset(item.getAsJsonObject()) : null; + + if (asset != null) { + assets.add(asset); + } + + if (asset.isInstallationFileAsset()) { + installationFileAsset = asset; + } + }); + } + + public ZonedDateTime getCreatedAt() { + if (createdAt != null) + return ZonedDateTime.parse(createdAt); + + return null; + } + + public boolean isPrerelease() { + return isPrerelease; + } + + public String getTagName() { + return tagName; + } + + public List getAssets() { + return assets; + } + + public GitHubReleaseAsset getInstallationFileAsset() { + return installationFileAsset; + } + + public String getId() { + return id; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof GitHubRelease ? getId().equals(((GitHubRelease) obj).getId()) : false; + } + +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/GitHubReleaseAsset.java b/src/main/java/it/unibz/inf/ontouml/vp/model/GitHubReleaseAsset.java new file mode 100644 index 00000000..1fd7a0a4 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/GitHubReleaseAsset.java @@ -0,0 +1,74 @@ +package it.unibz.inf.ontouml.vp.model; + +import com.google.gson.JsonObject; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class GitHubReleaseAsset { + + final private static String PROP_NAME = "name"; + final private static String PROP_ID = "id"; + final private static String PROP_BROWSER_DOWNLOAD_URL = "browser_download_url"; + final private static String PROP_CONTENT_TYPE = "content_type"; + + final private static String CONTENT_TYPE_APPLICATION_ZIP = "application/zip"; + +// public JsonObject source; + + @Expose() + private String name; + + @SerializedName("assetId") + @Expose() + private String id; + + @Expose() + private String downloadUrl; + + @Expose() + private String contentType; + + public GitHubReleaseAsset() { + name = null; + id = null; + downloadUrl = null; + contentType = null; + } + + public GitHubReleaseAsset(JsonObject source) { + if(source == null) { + throw new NullPointerException(); + } + + name = source.get(PROP_NAME).getAsString(); + id = source.get(PROP_ID).getAsString(); + downloadUrl = source.get(PROP_BROWSER_DOWNLOAD_URL).getAsString(); + contentType = source.get(PROP_CONTENT_TYPE).getAsString(); + } + + public String getName() { + return name; + } + + public String getDownloadUrl() { + return downloadUrl; + } + + public String getId() { + return id; + } + + public String getContentType() { + return contentType; + } + + public boolean isInstallationFileAsset() { + return getContentType().equals(CONTENT_TYPE_APPLICATION_ZIP); + } + + @Override + public boolean equals(Object obj) { + return obj instanceof GitHubRelease ? getId().equals(((GitHubRelease) obj).getId()) : false; + } + +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/ProjectConfigurations.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ProjectConfigurations.java similarity index 99% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/ProjectConfigurations.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/ProjectConfigurations.java index ea9715ba..f39ca880 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/ProjectConfigurations.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ProjectConfigurations.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.utils; +package it.unibz.inf.ontouml.vp.model; import java.util.HashSet; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/ServerRequest.java b/src/main/java/it/unibz/inf/ontouml/vp/model/ServerRequest.java similarity index 87% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/ServerRequest.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/ServerRequest.java index c2bc3eec..0049a059 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/ServerRequest.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/ServerRequest.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.utils; +package it.unibz.inf.ontouml.vp.model; public class ServerRequest implements Runnable { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Association.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java similarity index 99% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Association.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java index e1a370aa..e7a94acf 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Association.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Association.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import java.util.ArrayList; import java.util.HashSet; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/AssociationClass.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/AssociationClass.java similarity index 96% rename from src/main/java/it/unibz/inf/ontouml/vp/model/AssociationClass.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/AssociationClass.java index e7b76a2b..cf47d771 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/AssociationClass.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/AssociationClass.java @@ -1,10 +1,10 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; import com.vp.plugin.model.IAssociationClass; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; import java.util.ArrayList; import java.util.List; @@ -70,7 +70,7 @@ public AssociationClass(IAssociationClass source) { Property sourceEnd = new Property(source, source.getFrom()); Property targetEnd = new Property(source, source.getTo()); - addStereotype(StereotypeUtils.STR_DERIVATION); + addStereotype(StereotypesManager.STR_DERIVATION); addProperty(sourceEnd); addProperty(targetEnd); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Class.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Class.java similarity index 92% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Class.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Class.java index bdb67265..72f759e7 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Class.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Class.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import java.util.ArrayList; import java.util.Arrays; @@ -29,7 +29,7 @@ import com.vp.plugin.model.ITaggedValue; import com.vp.plugin.model.ITaggedValueContainer; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; /** * Implementation of ModelElement to handle IClass and IDataType objects to be @@ -122,7 +122,7 @@ public Class(IClass source) { addStereotype(stereotypes[i]); } - if (this.stereotypes != null && this.stereotypes.contains(StereotypeUtils.STR_ENUMERATION)) { + if (this.stereotypes != null && this.stereotypes.contains(StereotypesManager.STR_ENUMERATION)) { IEnumerationLiteral[] literalArray = source.toEnumerationLiteralArray(); for (int i = 0; literalArray != null && i < literalArray.length; i++) addLiteral(new Literal(literalArray[i])); @@ -146,7 +146,7 @@ public Class(IClass source) { public Class(IDataType source) { this((IModelElement) source); - addStereotype(StereotypeUtils.STR_DATATYPE); + addStereotype(StereotypesManager.STR_DATATYPE); setAbstract(false); setDerived(false); @@ -181,7 +181,7 @@ public Class(IClass source, HashSet modelElements) { addStereotype(stereotypes[i]); } - if (this.stereotypes != null && this.stereotypes.contains(StereotypeUtils.STR_ENUMERATION)) { + if (this.stereotypes != null && this.stereotypes.contains(StereotypesManager.STR_ENUMERATION)) { IEnumerationLiteral[] literalArray = source.toEnumerationLiteralArray(); for (int i = 0; literalArray != null && i < literalArray.length; i++) addLiteral(new Literal(literalArray[i])); @@ -463,7 +463,7 @@ public static void setRestrictedTo(IClass _class, String restrictions) { final ITaggedValue value = (ITaggedValue) values.next(); if( - value.getName().equals(StereotypeUtils.PROPERTY_RESTRICTED_TO) + value.getName().equals(StereotypesManager.PROPERTY_RESTRICTED_TO) ) { final String notNull = restrictions != null ? restrictions : ""; final List sortList = Arrays.asList(notNull.split("\\s+")); @@ -484,19 +484,19 @@ public static void setRestrictedTo(IClass _class, String restrictions) { } private static void setDefaultRestrictedTo(IClass element, String stereotypeName) { - final String defaultNature = StereotypeUtils.getDefaultRestrictedTo(stereotypeName); + final String defaultNature = StereotypesManager.getDefaultRestrictedTo(stereotypeName); setRestrictedTo(element, defaultNature); } public static void setDefaultRestrictedTo(IClass _class) { setDefaultRestrictedTo(_class, - StereotypeUtils.getUniqueStereotypeName(_class)); + StereotypesManager.getUniqueStereotypeName(_class)); } public static String getRestrictedTo(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue restrictedTo = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_RESTRICTED_TO) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_RESTRICTED_TO) : null; return restrictedTo != null ? restrictedTo.getValueAsString() : null; @@ -521,7 +521,7 @@ public static String getRestrictedTo(Set classes) { public static boolean hasRestrictedTo(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue restrictedTo = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_RESTRICTED_TO) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_RESTRICTED_TO) : null; return restrictedTo != null; @@ -530,7 +530,7 @@ public static boolean hasRestrictedTo(IClass _class) { public static String getOrder(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue order = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_ORDER) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_ORDER) : null; return order != null ? order.getValueAsString() : null ; @@ -539,7 +539,7 @@ public static String getOrder(IClass _class) { public static void setOrder(IClass _class, String newOrder) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue order = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_ORDER) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_ORDER) : null; if (order != null) { @@ -550,7 +550,7 @@ public static void setOrder(IClass _class, String newOrder) { public static boolean hasOrder(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue order = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_ORDER) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_ORDER) : null; return order != null; @@ -559,7 +559,7 @@ public static boolean hasOrder(IClass _class) { public static boolean getIsPowertype(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue isPowertype = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_IS_POWERTYPE) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_IS_POWERTYPE) : null; final String isPowertypeValue = isPowertype != null ? isPowertype.getValueAsString() : "" ; @@ -570,7 +570,7 @@ public static boolean getIsPowertype(IClass _class) { public static void setIsPowertype(IClass _class, boolean isPowertypeValue) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue isPowertype = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_IS_POWERTYPE) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_IS_POWERTYPE) : null; if (isPowertype != null) { @@ -581,7 +581,7 @@ public static void setIsPowertype(IClass _class, boolean isPowertypeValue) { public static boolean hasIsPowertype(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue isPowertype = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_IS_POWERTYPE) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_IS_POWERTYPE) : null; return isPowertype != null; @@ -590,7 +590,7 @@ public static boolean hasIsPowertype(IClass _class) { public static boolean getIsExtensional(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue isExtensional = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_IS_EXTENSIONAL) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_IS_EXTENSIONAL) : null; final String isExtensionalValue = isExtensional != null ? isExtensional.getValueAsString() : "" ; @@ -601,7 +601,7 @@ public static boolean getIsExtensional(IClass _class) { public static void setIsExtensional(IClass _class, boolean isExtensionalValue) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue isExtensional = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_IS_EXTENSIONAL) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_IS_EXTENSIONAL) : null; if (isExtensional != null) { @@ -612,7 +612,7 @@ public static void setIsExtensional(IClass _class, boolean isExtensionalValue) { public static boolean hasIsExtensional(IClass _class) { final ITaggedValueContainer container = _class.getTaggedValues(); final ITaggedValue isExtensional = container != null ? - container.getTaggedValueByName(StereotypeUtils.PROPERTY_IS_EXTENSIONAL) : + container.getTaggedValueByName(StereotypesManager.PROPERTY_IS_EXTENSIONAL) : null; return isExtensional != null; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Generalization.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Generalization.java similarity index 98% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Generalization.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Generalization.java index d8539fbb..128f7624 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Generalization.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Generalization.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/GeneralizationSet.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/GeneralizationSet.java similarity index 99% rename from src/main/java/it/unibz/inf/ontouml/vp/model/GeneralizationSet.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/GeneralizationSet.java index bbf58a07..f85cd0b5 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/GeneralizationSet.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/GeneralizationSet.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Literal.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Literal.java similarity index 97% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Literal.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Literal.java index 1212d5e4..2fc3b757 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Literal.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Literal.java @@ -1,4 +1,4 @@ - package it.unibz.inf.ontouml.vp.model; + package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Model.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Model.java similarity index 99% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Model.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Model.java index 0fc657b7..2ad8eeb0 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Model.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Model.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import java.util.ArrayList; import java.util.HashSet; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/ModelElement.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/ModelElement.java similarity index 95% rename from src/main/java/it/unibz/inf/ontouml/vp/model/ModelElement.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/ModelElement.java index f6cc1f04..aefff2fc 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/ModelElement.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/ModelElement.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; @@ -8,7 +8,7 @@ import com.vp.plugin.model.ITaggedValueContainer; import com.vp.plugin.model.factory.IModelElementFactory; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; import java.util.Arrays; import java.util.HashSet; @@ -172,10 +172,10 @@ public static JsonObject transformPropertyAssignments(IModelElement sourceElemen JsonObject obj = new JsonObject(); ITaggedValue[] lTaggedValues = lContainer.toTaggedValueArray(); List ignoredClassValues = - Arrays.asList(new String[]{StereotypeUtils.PROPERTY_RESTRICTED_TO, - StereotypeUtils.PROPERTY_IS_EXTENSIONAL, - StereotypeUtils.PROPERTY_IS_POWERTYPE, - StereotypeUtils.PROPERTY_ORDER}); + Arrays.asList(new String[]{StereotypesManager.PROPERTY_RESTRICTED_TO, + StereotypesManager.PROPERTY_IS_EXTENSIONAL, + StereotypesManager.PROPERTY_IS_POWERTYPE, + StereotypesManager.PROPERTY_ORDER}); for (int i = 0; lTaggedValues != null && i < lTaggedValues.length; i++) { if (ignoredClassValues.contains(lTaggedValues[i].getName())) { diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Package.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Package.java similarity index 93% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Package.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Package.java index 6d3d0f83..806862b8 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Package.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Package.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; @@ -67,12 +67,6 @@ public Package(IPackage source) { case IModelElementFactory.MODEL_TYPE_CLASS: addElement(new Class((IClass) child)); break; - // TODO Add remaining elements, maybe by adding these to relation's - // source's package. - // case IModelElementFactory.MODEL_TYPE_GENERALIZATION: - // case IModelElementFactory.MODEL_TYPE_ASSOCIATION: - // case IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS: - // case IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET: } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Property.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java similarity index 99% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Property.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java index 69eb03b1..1efc0e14 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Property.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Property.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/model/Reference.java b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Reference.java similarity index 95% rename from src/main/java/it/unibz/inf/ontouml/vp/model/Reference.java rename to src/main/java/it/unibz/inf/ontouml/vp/model/uml/Reference.java index 14e2f9c6..a88a154e 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/model/Reference.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/model/uml/Reference.java @@ -1,4 +1,4 @@ -package it.unibz.inf.ontouml.vp.model; +package it.unibz.inf.ontouml.vp.model.uml; import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ActionIds.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/ActionIdManager.java similarity index 85% rename from src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ActionIds.java rename to src/main/java/it/unibz/inf/ontouml/vp/utils/ActionIdManager.java index 292b4ef6..bf891917 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/features/constraints/ActionIds.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/utils/ActionIdManager.java @@ -1,8 +1,6 @@ -package it.unibz.inf.ontouml.vp.features.constraints; +package it.unibz.inf.ontouml.vp.utils; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; - -public final class ActionIds { +public final class ActionIdManager { // Class stereotypes (ordered as in plugin.xml) public static final String TYPE = "it.unibz.inf.ontouml.vp.addTypeStereotype"; @@ -120,45 +118,45 @@ public final class ActionIds { public static String classStereotypeToActionID(String stereotype) { switch(stereotype) { - case StereotypeUtils.STR_TYPE: + case StereotypesManager.STR_TYPE: return TYPE; - case StereotypeUtils.STR_HISTORICAL_ROLE: + case StereotypesManager.STR_HISTORICAL_ROLE: return HISTORICAL_ROLE; - case StereotypeUtils.STR_HISTORICAL_ROLE_MIXIN: + case StereotypesManager.STR_HISTORICAL_ROLE_MIXIN: return HISTORICAL_ROLE_MIXIN; - case StereotypeUtils.STR_EVENT: + case StereotypesManager.STR_EVENT: return EVENT; - case StereotypeUtils.STR_SITUATION: + case StereotypesManager.STR_SITUATION: return SITUATION; - case StereotypeUtils.STR_CATEGORY: + case StereotypesManager.STR_CATEGORY: return CATEGORY; - case StereotypeUtils.STR_MIXIN: + case StereotypesManager.STR_MIXIN: return MIXIN; - case StereotypeUtils.STR_ROLE_MIXIN: + case StereotypesManager.STR_ROLE_MIXIN: return ROLE_MIXIN; - case StereotypeUtils.STR_PHASE_MIXIN: + case StereotypesManager.STR_PHASE_MIXIN: return PHASE_MIXIN; - case StereotypeUtils.STR_KIND: + case StereotypesManager.STR_KIND: return KIND; - case StereotypeUtils.STR_COLLECTIVE: + case StereotypesManager.STR_COLLECTIVE: return COLLECTIVE; - case StereotypeUtils.STR_QUANTITY: + case StereotypesManager.STR_QUANTITY: return QUANTITY; - case StereotypeUtils.STR_RELATOR: + case StereotypesManager.STR_RELATOR: return RELATOR; - case StereotypeUtils.STR_QUALITY: + case StereotypesManager.STR_QUALITY: return QUALITY; - case StereotypeUtils.STR_MODE: + case StereotypesManager.STR_MODE: return MODE; - case StereotypeUtils.STR_SUBKIND: + case StereotypesManager.STR_SUBKIND: return SUBKIND; - case StereotypeUtils.STR_ROLE: + case StereotypesManager.STR_ROLE: return ROLE; - case StereotypeUtils.STR_PHASE: + case StereotypesManager.STR_PHASE: return PHASE; - case StereotypeUtils.STR_ENUMERATION: + case StereotypesManager.STR_ENUMERATION: return ENUMERATION; - case StereotypeUtils.STR_DATATYPE: + case StereotypesManager.STR_DATATYPE: return DATATYPE; default: return null; @@ -167,41 +165,41 @@ public static String classStereotypeToActionID(String stereotype) { public static String associationStereotypeToActionID(String stereotype) { switch(stereotype) { - case StereotypeUtils.STR_INSTANTIATION: + case StereotypesManager.STR_INSTANTIATION: return INSTANTIATION; - case StereotypeUtils.STR_TERMINATION: + case StereotypesManager.STR_TERMINATION: return TERMINATION; - case StereotypeUtils.STR_PARTICIPATIONAL: + case StereotypesManager.STR_PARTICIPATIONAL: return PARTICIPATIONAL; - case StereotypeUtils.STR_PARTICIPATION: + case StereotypesManager.STR_PARTICIPATION: return PARTICIPATION; - case StereotypeUtils.STR_HISTORICAL_DEPENDENCE: + case StereotypesManager.STR_HISTORICAL_DEPENDENCE: return HISTORICAL_DEPENDENCE; - case StereotypeUtils.STR_CREATION: + case StereotypesManager.STR_CREATION: return CREATION; - case StereotypeUtils.STR_MANIFESTATION: + case StereotypesManager.STR_MANIFESTATION: return MANIFESTATION; - case StereotypeUtils.STR_BRINGS_ABOUT: + case StereotypesManager.STR_BRINGS_ABOUT: return BRINGS_ABOUT; - case StereotypeUtils.STR_TRIGGERS: + case StereotypesManager.STR_TRIGGERS: return TRIGGERS; - case StereotypeUtils.STR_SUB_QUANTITY_OF: + case StereotypesManager.STR_SUB_QUANTITY_OF: return SUB_QUANTITY_OF; - case StereotypeUtils.STR_SUB_COLLECTION_OF: + case StereotypesManager.STR_SUB_COLLECTION_OF: return SUB_COLLECTION_OF; - case StereotypeUtils.STR_MEMBER_OF: + case StereotypesManager.STR_MEMBER_OF: return MEMBER_OF; - case StereotypeUtils.STR_MEDIATION: + case StereotypesManager.STR_MEDIATION: return MEDIATION; - case StereotypeUtils.STR_MATERIAL: + case StereotypesManager.STR_MATERIAL: return MATERIAL; - case StereotypeUtils.STR_EXTERNAL_DEPENDENCE: + case StereotypesManager.STR_EXTERNAL_DEPENDENCE: return EXTERNAL_DEPENDENCE; - case StereotypeUtils.STR_COMPONENT_OF: + case StereotypesManager.STR_COMPONENT_OF: return COMPONENT_OF; - case StereotypeUtils.STR_COMPARATIVE: + case StereotypesManager.STR_COMPARATIVE: return COMPARATIVE; - case StereotypeUtils.STR_CHARACTERIZATION: + case StereotypesManager.STR_CHARACTERIZATION: return CHARACTERIZATION; default: return null; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/CollectionAdapter.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/CollectionAdapter.java deleted file mode 100644 index 42c9cf46..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/CollectionAdapter.java +++ /dev/null @@ -1,29 +0,0 @@ -package it.unibz.inf.ontouml.vp.utils; - -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; -import java.util.Collection; - -// TODO Check whether this class is indeed necessary. -public class CollectionAdapter implements JsonSerializer> { - - @Override - public JsonElement serialize(Collection src, Type typeOfSrc, JsonSerializationContext context) { - if (src == null || src.isEmpty()) - return null; - - JsonArray array = new JsonArray(); - - for (Object child : src) { - JsonElement element = context.serialize(child); - array.add(element); - } - - return array; - } - -} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/Configurations.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/Configurations.java deleted file mode 100644 index c20bf234..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/Configurations.java +++ /dev/null @@ -1,156 +0,0 @@ -package it.unibz.inf.ontouml.vp.utils; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonSyntaxException; -import com.google.gson.annotations.Expose; -import com.google.gson.annotations.SerializedName; -import com.vp.plugin.ApplicationManager; -import com.vp.plugin.model.IProject; -import it.unibz.inf.ontouml.vp.OntoUMLPlugin; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; - -/** - * - * OntoUML Plugin configuration utility, allows persisting - * user preferences on the functionalities enabled by the plugin. - * - * @author Claudenir Fonseca - * - */ -public class Configurations { - - private static final String CONFIG_FILE_NAME = ".ontouml.config.json"; - - private static Configurations instance; - - @SerializedName("projects") - @Expose() - private List projects; - - private Configurations() { - this.projects = new ArrayList(); - } - - private List getProjectConfigurationsList() { - return projects; - } - - private boolean addProjectConfigurations(ProjectConfigurations projectConfigurations) { - return getProjectConfigurationsList().add(projectConfigurations); - } - - /** - * - * Returns singleton instance of the class. - * - * @return configurations - * - */ - public static Configurations getInstance() { - if(instance == null) { - final ApplicationManager application = ApplicationManager.instance(); - final File workspace = application.getWorkspaceLocation(); - final File configurationsFile = new File(workspace, CONFIG_FILE_NAME); - - if(configurationsFile.exists()) { - String json = ""; - try { - json = new String(Files.readAllBytes(configurationsFile.toPath())); - Gson gson = new Gson(); - instance = gson.fromJson(json, Configurations.class); - } - catch (Exception e) { - if(e instanceof IOException) - application.getViewManager().showMessage("Unable to load configuration file (" + OntoUMLPlugin.PLUGIN_NAME + ").\n"); - else if(e instanceof JsonSyntaxException ) - application.getViewManager().showMessage("Configuration file ill-formed (" + OntoUMLPlugin.PLUGIN_NAME + ").\n"); - else - application.getViewManager().showMessage("Unknown error while reading configuration file (" + OntoUMLPlugin.PLUGIN_NAME + ").\n"); - - e.printStackTrace(); - } - } - - if(instance==null) - instance = new Configurations(); - } - - return instance; - } - - /** - * - * Persists user preferences on Visual Paradigm's workspace. - * - */ - public void save() { - final ApplicationManager application = ApplicationManager.instance(); - final File workspace = application.getWorkspaceLocation(); - final File configurationsFile = new File(workspace, CONFIG_FILE_NAME); - final FileWriter fw; - final Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().setPrettyPrinting().create(); - final String json = gson.toJson(this); - - try { - if(!configurationsFile.exists()) { - configurationsFile.createNewFile(); - } - - fw = new FileWriter(configurationsFile); - fw.write(json); - fw.close(); - } catch (IOException e) { - application.getViewManager().showMessage("Unable save " - + OntoUMLPlugin.PLUGIN_NAME - + " configurations."); - e.printStackTrace(); - } - } - - /** - * - * Retrieves the configurations of the current project. - * - * @return current project's configurations. - * - */ - public ProjectConfigurations getProjectConfigurations() { - final IProject current = ApplicationManager.instance().getProjectManager().getProject(); - - return getProjectConfigurations(current.getId()); - } - - /** - * - * Retrieves the project configurations given the provided ID. - * If no previous configurations is present, a new instance of - * ProjectConfigurations is returned with default - * settings. - * - * @param projectId - Interest project's ID. - * - * @return current project's configurations. - * - * - */ - public ProjectConfigurations getProjectConfigurations(String projectId) { - for (ProjectConfigurations projectConfigurations : getProjectConfigurationsList()) { - if(projectConfigurations.getId().equals(projectId)) { - return projectConfigurations; - } - } - - ProjectConfigurations projectConfigurations = new ProjectConfigurations(projectId); - addProjectConfigurations(projectConfigurations); - - return projectConfigurations; - } - -} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLConstraintsManager.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLConstraintsManager.java new file mode 100644 index 00000000..63667d24 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/utils/OntoUMLConstraintsManager.java @@ -0,0 +1,110 @@ +package it.unibz.inf.ontouml.vp.utils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import com.vp.plugin.ApplicationManager; +import com.vp.plugin.VPPluginInfo; + +import it.unibz.inf.ontouml.vp.OntoUMLPlugin; + +public class OntoUMLConstraintsManager { + + final private static Type mapOfListsType = new TypeToken>>() {}.getType(); + + private static String GENERALIZATION_CONSTRAINTS_FILENAME = "generalization_constraints.json"; + private static String ASSOCIATION_CONSTRAINTS_FILENAME = "association_constraints.json"; + + private static String ALLOWED_SUBCLASSES = "allowedSubClassesFor"; + private static String ALLOWED_SUPERCLASSES = "allowedSuperClassesFor"; + + private static Map> allowedSuperClassesFor, allowedSubClassesFor; + + private static Map> associationConstraints; + + + private static void loadConstraints() { + try { + final ApplicationManager app = ApplicationManager.instance(); + final VPPluginInfo pluginInfo = app.getPluginInfo(OntoUMLPlugin.PLUGIN_ID); + + File generalizationsConstraintsFile = new File(pluginInfo.getPluginDir(),GENERALIZATION_CONSTRAINTS_FILENAME); + File associationConstraintsFile = new File(pluginInfo.getPluginDir(),ASSOCIATION_CONSTRAINTS_FILENAME); + + final JsonParser parser = new JsonParser(); + final JsonObject gConstraintsObject = parser.parse(new FileReader(generalizationsConstraintsFile)).getAsJsonObject(); + final JsonObject aConstraintsObject = parser.parse(new FileReader(associationConstraintsFile)).getAsJsonObject(); + + final Gson gson = new Gson(); + allowedSubClassesFor = gson.fromJson(gConstraintsObject.getAsJsonObject(ALLOWED_SUBCLASSES), mapOfListsType); + allowedSuperClassesFor = gson.fromJson(gConstraintsObject.getAsJsonObject(ALLOWED_SUPERCLASSES), mapOfListsType); + associationConstraints = gson.fromJson(aConstraintsObject, mapOfListsType); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public static List getAllowedStereotypeActionsOnGeneral(String stereotype) { + if(allowedSuperClassesFor == null || allowedSubClassesFor == null) { + loadConstraints(); + } + + List allowedStereotypes = allowedSubClassesFor.get(stereotype); + + if(allowedStereotypes == null) { + allowedStereotypes = new ArrayList(); + } + + return allowedStereotypes + .stream() + .map(allowed -> ActionIdManager.classStereotypeToActionID(allowed)) + .collect(Collectors.toList()); + } + + public static List getAllowedStereotypeActionsSpecific(String stereotype) { + if(allowedSuperClassesFor == null || allowedSubClassesFor == null) { + loadConstraints(); + } + + List allowedStereotypes = allowedSuperClassesFor.get(stereotype); + + if(allowedStereotypes == null) { + allowedStereotypes = new ArrayList(); + } + + return allowedStereotypes + .stream() + .map(allowed -> ActionIdManager.classStereotypeToActionID(allowed)) + .collect(Collectors.toList()); + } + + + public static List getAllowedStereotypeActionsOnAssociation(String sourceStereotype, String targetStereotype) { + if(associationConstraints == null) { + loadConstraints(); + } + + List allowedStereotypes = associationConstraints.get(sourceStereotype + ":" + targetStereotype); + + if(allowedStereotypes == null) { + allowedStereotypes = new ArrayList(); + } + + return allowedStereotypes + .stream() + .map(allowed -> ActionIdManager.associationStereotypeToActionID(allowed)) + .collect(Collectors.toList()); + } + +} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/SmartColoring.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/SmartColoringUtils.java similarity index 69% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/SmartColoring.java rename to src/main/java/it/unibz/inf/ontouml/vp/utils/SmartColoringUtils.java index f6ea8c51..841cc2d9 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/SmartColoring.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/utils/SmartColoringUtils.java @@ -6,15 +6,12 @@ import java.util.Set; import java.util.stream.Collectors; -import com.vp.plugin.ApplicationManager; import com.vp.plugin.diagram.IDiagramElement; import com.vp.plugin.diagram.shape.IClassUIModel; import com.vp.plugin.model.IClass; -import com.vp.plugin.model.IModelElement; -import com.vp.plugin.model.IProject; -import com.vp.plugin.model.factory.IModelElementFactory; -import it.unibz.inf.ontouml.vp.model.Class; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.uml.Class; /** * Implementation of the coloring feature @@ -23,7 +20,7 @@ * @author Claudenir Fonseca * @author Tiago Prince Sales */ -public class SmartColoring { +public class SmartColoringUtils { public static final Color COLOR_FOR_ABSTRACT = new Color(255, 255, 255); public static final Color COLOR_FOR_COLLECTIVE = new Color(255, 218, 221); @@ -43,23 +40,6 @@ public class SmartColoring { public static final Color COLOR_FOR_TYPE = new Color(211, 211, 252); public static final Color COLOR_FOR_NON_SPECIFIC = new Color(224, 224, 224); - /** - * Runs twice over the diagram and paint all the elements. - */ - public static void paintAll() { - if (!Configurations.getInstance().getProjectConfigurations().isAutomaticColoringEnabled()) { - return; - } - - final IProject project = ApplicationManager.instance().getProjectManager().getProject(); - final IModelElement[] modelElements = project - .toAllLevelModelElementArray(IModelElementFactory.MODEL_TYPE_CLASS); - - for (int j = 0; modelElements != null && j < modelElements.length; j++) { - SmartColoring.paint((IClass) modelElements[j]); - } - } - /** * Paints occurrences of a class based on the "restrictTo" meta-property. * Affects class occurrences in all diagrams. No effect whenever auto-coloring @@ -103,11 +83,11 @@ public static void paint(IClassUIModel classDiagramElement) { * @return the color of the class */ private static Color getColor(IClass _class) { - final String stereotype = StereotypeUtils.getUniqueStereotypeName(_class); + final String stereotype = StereotypesManager.getUniqueStereotypeName(_class); String restrictedTo = Class.getRestrictedTo(_class); if (restrictedTo == null || restrictedTo.isEmpty()) { - final Set allStereotypes = StereotypeUtils.getOntoUMLClassStereotypeNames(); + final Set allStereotypes = StereotypesManager.getOntoUMLClassStereotypeNames(); if (!allStereotypes.contains(stereotype)) { return null; @@ -116,44 +96,44 @@ private static Color getColor(IClass _class) { } } - final Set ultimateSortalStereotypes = StereotypeUtils.getUltimateSortalStereotypeNames(); + final Set ultimateSortalStereotypes = StereotypesManager.getUltimateSortalStereotypeNames(); switch (restrictedTo) { - case StereotypeUtils.RESTRICTED_TO_ABSTRACT: + case StereotypesManager.RESTRICTED_TO_ABSTRACT: return COLOR_FOR_ABSTRACT; - case StereotypeUtils.RESTRICTED_TO_COLLECTIVE: + case StereotypesManager.RESTRICTED_TO_COLLECTIVE: return ultimateSortalStereotypes.contains(stereotype) ? COLOR_FOR_COLLECTIVE_DARK : COLOR_FOR_COLLECTIVE; - case StereotypeUtils.RESTRICTED_TO_EVENT: + case StereotypesManager.RESTRICTED_TO_EVENT: return COLOR_FOR_EVENT; - case StereotypeUtils.RESTRICTED_TO_SITUATION: + case StereotypesManager.RESTRICTED_TO_SITUATION: return COLOR_FOR_SITUATION; - case StereotypeUtils.RESTRICTED_TO_MODE: + case StereotypesManager.RESTRICTED_TO_MODE: return ultimateSortalStereotypes.contains(stereotype) ? COLOR_FOR_MODE_DARK : COLOR_FOR_MODE; - case StereotypeUtils.RESTRICTED_TO_FUNCTIONAL_COMPLEX: + case StereotypesManager.RESTRICTED_TO_FUNCTIONAL_COMPLEX: return ultimateSortalStereotypes.contains(stereotype) ? COLOR_FOR_FUNCTIONAL_COMPLEX_DARK : COLOR_FOR_FUNCTIONAL_COMPLEX; - case StereotypeUtils.RESTRICTED_TO_QUALITY: + case StereotypesManager.RESTRICTED_TO_QUALITY: return ultimateSortalStereotypes.contains(stereotype) ? COLOR_FOR_QUALITY_DARK : COLOR_FOR_QUALITY; - case StereotypeUtils.RESTRICTED_TO_QUANTITY: + case StereotypesManager.RESTRICTED_TO_QUANTITY: return ultimateSortalStereotypes.contains(stereotype) ? COLOR_FOR_QUANTITY_DARK : COLOR_FOR_QUANTITY; - case StereotypeUtils.RESTRICTED_TO_RELATOR: + case StereotypesManager.RESTRICTED_TO_RELATOR: return ultimateSortalStereotypes.contains(stereotype) ? COLOR_FOR_RELATOR_DARK : COLOR_FOR_RELATOR; - case StereotypeUtils.RESTRICTED_TO_TYPE: + case StereotypesManager.RESTRICTED_TO_TYPE: return COLOR_FOR_TYPE; } final List restrictedToList = Arrays.stream(restrictedTo.split("\\s+")).map(s -> s.trim()) .collect(Collectors.toList()); - final List objectNatures = Arrays.asList(StereotypeUtils.RESTRICTED_TO_FUNCTIONAL_COMPLEX, - StereotypeUtils.RESTRICTED_TO_COLLECTIVE, StereotypeUtils.RESTRICTED_TO_QUANTITY); + final List objectNatures = Arrays.asList(StereotypesManager.RESTRICTED_TO_FUNCTIONAL_COMPLEX, + StereotypesManager.RESTRICTED_TO_COLLECTIVE, StereotypesManager.RESTRICTED_TO_QUANTITY); if (objectNatures.containsAll(restrictedToList)) { return COLOR_FOR_FUNCTIONAL_COMPLEX; } - final List intrinsicNature = Arrays.asList(StereotypeUtils.RESTRICTED_TO_MODE, - StereotypeUtils.RESTRICTED_TO_QUALITY); + final List intrinsicNature = Arrays.asList(StereotypesManager.RESTRICTED_TO_MODE, + StereotypesManager.RESTRICTED_TO_QUALITY); if (intrinsicNature.containsAll(restrictedToList)) { return COLOR_FOR_MODE; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/StereotypeUtils.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/StereotypesManager.java similarity index 99% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/StereotypeUtils.java rename to src/main/java/it/unibz/inf/ontouml/vp/utils/StereotypesManager.java index e768ce25..f4cd32b7 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/StereotypeUtils.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/utils/StereotypesManager.java @@ -20,7 +20,7 @@ import com.vp.plugin.model.ITaggedValueDefinitionContainer; import com.vp.plugin.model.factory.IModelElementFactory; -public class StereotypeUtils { +public class StereotypesManager { public static Map STEREOTYPE_ELEMENTS = null; @@ -367,7 +367,6 @@ public static List getRestrictionsList() { public static void applyStereotype(IModelElement element, String stereotypeName) { final IStereotype stereotype = getStereotype(stereotypeName); - // TODO: check the necessity of throwing some exception here if (stereotype == null || !element.getModelType().equals(stereotype.getBaseType())){ return; } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/utils/ViewUtils.java b/src/main/java/it/unibz/inf/ontouml/vp/utils/ViewManagerUtils.java similarity index 74% rename from src/main/java/it/unibz/inf/ontouml/vp/utils/ViewUtils.java rename to src/main/java/it/unibz/inf/ontouml/vp/utils/ViewManagerUtils.java index 282cc267..a0f86f53 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/utils/ViewUtils.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/utils/ViewManagerUtils.java @@ -2,11 +2,6 @@ import java.awt.FileDialog; import java.awt.Frame; -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -15,15 +10,16 @@ import java.nio.file.Paths; import java.sql.Timestamp; import java.util.ArrayList; -import java.util.Iterator; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JList; -import javax.swing.JMenuItem; import javax.swing.JOptionPane; -import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import com.google.gson.JsonArray; @@ -33,7 +29,6 @@ import com.google.gson.JsonSyntaxException; import com.vp.plugin.ApplicationManager; import com.vp.plugin.DiagramManager; -import com.vp.plugin.ProjectManager; import com.vp.plugin.ViewManager; import com.vp.plugin.diagram.IClassDiagramUIModel; import com.vp.plugin.diagram.IDiagramElement; @@ -42,6 +37,10 @@ import com.vp.plugin.model.IProject; import it.unibz.inf.ontouml.vp.OntoUMLPlugin; +import it.unibz.inf.ontouml.vp.listeners.IssueLogMenuListener; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.GitHubRelease; +import it.unibz.inf.ontouml.vp.model.ProjectConfigurations; import it.unibz.inf.ontouml.vp.views.HTMLEnabledMessage; /** @@ -53,14 +52,12 @@ * @author Victor Viola * */ -public class ViewUtils { +public class ViewManagerUtils { public static final String SCOPE_PLUGIN = "OntoUML"; - // public static final String SCOPE_ALL_PLUGINS = ""; public static final String SCOPE_VERIFICATION = "Verification Log"; public static final String SCOPE_DEVELOPMENT_LOG = "DevLog"; - // images public static final String SIMPLE_LOGO = "simple_logo"; public static final String SIMPLE_LOGO_FILENAME = "ontouml-simple-logo.png"; public static final String NAVIGATION_LOGO = "navigation"; @@ -84,41 +81,16 @@ public class ViewUtils { public static final String ATTRIBUTE_LOGO = "attribute"; public static final String ATTRIBUTE_LOGO_FILENAME = "attribute.png"; - // buttons - public static final String ADD_LOGO = "add"; - public static final String ASTERISK_LOGO = "asterisk"; - public static final String SUBTRACT_LOGO = "subtract"; - public static final String ADD_LOGO_FILENAME = "add.png"; - public static final String ASTERISK_LOGO_FILENAME = "asterisk.png"; - public static final String SUBTRACT_LOGO_FILENAME = "subtract.png"; - - public static void log(String message) { - ApplicationManager.instance().getViewManager().showMessage(timestamp() + message); - } - - public static void log(String message, String scope) { - ApplicationManager.instance().getViewManager().showMessage(timestamp() + message, scope); - } - public static void simpleLog(String message) { ApplicationManager.instance().getViewManager().showMessage(message); } - public static void simpleLog(String message, String scope) { - ApplicationManager.instance().getViewManager().showMessage(message, scope); - } - - public static void clearLog(String scope) { - ApplicationManager.instance().getViewManager().clearMessages(scope); - } - public static void simpleDialog(String title, String message) { ApplicationManager.instance().getViewManager().showConfirmDialog(null, message, title, JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO))); } public static void cleanAndShowMessage(String message) { - ApplicationManager.instance().getViewManager().removeMessagePaneComponent(OntoUMLPlugin.PLUGIN_ID); ArrayList messageList = new ArrayList(); @@ -126,7 +98,7 @@ public static void cleanAndShowMessage(String message) { JList list = new JList<>(messageList.toArray()); JScrollPane parentContainer = new JScrollPane(list); ApplicationManager.instance().getViewManager().showMessagePaneComponent(OntoUMLPlugin.PLUGIN_ID, - ViewUtils.SCOPE_PLUGIN, parentContainer); + ViewManagerUtils.SCOPE_PLUGIN, parentContainer); } @@ -165,12 +137,6 @@ public static String getFilePath(String imageName) { return Paths.get(pluginDir.getAbsolutePath(), "icons", DATATYPE_LOGO_FILENAME).toFile().getAbsolutePath(); case ATTRIBUTE_LOGO: return Paths.get(pluginDir.getAbsolutePath(), "icons", ATTRIBUTE_LOGO_FILENAME).toFile().getAbsolutePath(); - case ADD_LOGO: - return Paths.get(pluginDir.getAbsolutePath(), "icons", ADD_LOGO_FILENAME).toFile().getAbsolutePath(); - case ASTERISK_LOGO: - return Paths.get(pluginDir.getAbsolutePath(), "icons", ASTERISK_LOGO_FILENAME).toFile().getAbsolutePath(); - case SUBTRACT_LOGO: - return Paths.get(pluginDir.getAbsolutePath(), "icons", SUBTRACT_LOGO_FILENAME).toFile().getAbsolutePath(); default: return null; } @@ -209,20 +175,10 @@ public static void logDiagramVerificationResponse(String responseMessage) { errorList.add(timestamp() + errorMessage.toString()); idModelElementList.add(id); } - // final JsonObject error = elem.getAsJsonObject(); - // final String id = error.getAsJsonObject("source").get("id").getAsString(); - - // if (isElementInCurrentDiagram(id)) { - // final String errorMessage = error.get("severity").getAsString() + ":" + " " + - // error.get("title").getAsString() + " " + - // error.get("description").getAsString(); - // errorList.add(timestamp() + errorMessage); - // idModelElementList.add(id); - // } } JList list = new JList<>(errorList.toArray()); - ContextMenuListener listener = new ContextMenuListener(idModelElementList, list); + IssueLogMenuListener listener = new IssueLogMenuListener(idModelElementList, list); list.addMouseListener(listener); list.addMouseMotionListener(listener); @@ -266,7 +222,7 @@ public static void logVerificationResponse(String responseMessage) { } JList list = new JList<>(errorList.toArray()); - ContextMenuListener listener = new ContextMenuListener(idModelElementList, list); + IssueLogMenuListener listener = new IssueLogMenuListener(idModelElementList, list); list.addMouseListener(listener); list.addMouseMotionListener(listener); @@ -372,21 +328,6 @@ public static boolean exportToGUFOIssueDialogWithOption(String msg, int httpCode } } - public static int smartPaintEnableDialog() { - return ApplicationManager.instance().getViewManager().showConfirmDialog(null, - "Smart Paint is disabled. Do you want to enable this feature?\n" - + "Warning: this feature will affect all diagrams within the project.", - "Smart Paint", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, - new ImageIcon(getFilePath(SIMPLE_LOGO))); - } - - public static int smartPaintConfirmationDialog() { - return ApplicationManager.instance().getViewManager().showConfirmDialog(null, - "Warning: this feature will affect all diagrams within the project.\n" + "Do you want to proceed?", - "Smart Paint", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, - new ImageIcon(getFilePath(SIMPLE_LOGO))); - } - public static void saveFile(BufferedReader buffer) throws IOException { final Configurations configs = Configurations.getInstance(); final ProjectConfigurations projectConfigurations = configs.getProjectConfigurations(); @@ -416,7 +357,7 @@ public static void saveFile(BufferedReader buffer) throws IOException { configs.save(); } - ViewUtils.cleanAndShowMessage("File saved successfuly."); + ViewManagerUtils.cleanAndShowMessage("File saved successfuly."); } public static String getCurrentClassDiagramName() { @@ -489,7 +430,7 @@ public static boolean isElementInAnyDiagram(String elementId) { final IProject project = ApplicationManager.instance().getProjectManager().getProject(); final IModelElement element = project.getModelElementById(elementId); final IDiagramElement[] diagramElements = element != null ? element.getDiagramElements() : null; - + return diagramElements != null && diagramElements.length > 0; } @@ -505,40 +446,38 @@ public static void highlightDiagramElement(String modelElementId) { final ApplicationManager app = ApplicationManager.instance(); final IProject project = app.getProjectManager().getProject(); final IModelElement modelElement = project.getModelElementById(modelElementId); - - if(modelElement == null) { - return ; + + if (modelElement == null) { + return; } - + final DiagramManager diagramManager = app.getDiagramManager(); final IDiagramElement[] diagramElements = modelElement.getDiagramElements(); IDiagramElement activeView = null; IDiagramElement masterView = null; IDiagramElement firstView = null; - - for (int i=0; diagramElements != null && i < diagramElements.length; i++) { + + for (int i = 0; diagramElements != null && i < diagramElements.length; i++) { IDiagramElement diagramElement = diagramElements[i]; - - if(diagramElement == null) { - continue ; + + if (diagramElement == null) { + continue; } - + firstView = firstView == null ? diagramElement : firstView; activeView = diagramElement.getDiagramUIModel().isOpened() ? diagramElement : activeView; masterView = diagramElement.isMasterView() ? diagramElement : masterView; - - if(activeView != null) { - break ; + + if (activeView != null) { + break; } } - - if(activeView != null) { + + if (activeView != null) { diagramManager.highlight(activeView); - } - else if(masterView != null) { + } else if (masterView != null) { diagramManager.highlight(masterView); - } - else if(firstView != null) { + } else if (firstView != null) { diagramManager.highlight(firstView); } } @@ -564,130 +503,104 @@ public static void reportBugErrorDialog(boolean isOperationNotAllowed) { vm.showConfirmDialog(null, new HTMLEnabledMessage(body), "Report Error", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO))); } - - public static void updateDialog() { - final ViewManager vm = ApplicationManager.instance().getViewManager(); - final StringBuilder builder = new StringBuilder(); - builder.append("Please select the ZIP file containing the release of the OntoUML Plguin that you wish to install.
"); - builder.append("The latest release is available at " + OntoUMLPlugin.PLUGIN_REPO +".

"); - builder.append("This procedure may take a couple of seconds."); - vm.showConfirmDialog(null, new HTMLEnabledMessage(builder.toString()), "Plugin Update", JOptionPane.DEFAULT_OPTION, - JOptionPane.PLAIN_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO))); - } - - public static void updateSuccessDialog() { - final ViewManager vm = ApplicationManager.instance().getViewManager(); - final String msg = "Plugin successfully updated.\nPlease reopen the application for the changes to take effect."; + public static GitHubRelease updateDialog() { + final Configurations config = Configurations.getInstance(); + final GitHubRelease lastestRelease = config.getLatestRelease(); - vm.showConfirmDialog(null, msg, "Plugin Update", JOptionPane.DEFAULT_OPTION, - JOptionPane.PLAIN_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO))); - } - - public static void updateErrorDialog() { - final ViewManager vm = ApplicationManager.instance().getViewManager(); - final StringBuilder builder = new StringBuilder(); - builder.append("Something went wrong during the update.
"); - builder.append("In case your plugin becomes unavailable, you may find instructions at " + OntoUMLPlugin.PLUGIN_REPO +".
"); - builder.append("In this page you can also report this error and help us to improve our plugin."); + final boolean isUpToDate = lastestRelease.getTagName().equals(OntoUMLPlugin.PLUGIN_VERSION_RELEASE); + String[] options; + String initialSelection; + StringBuilder msg = new StringBuilder(); - vm.showConfirmDialog(null, new HTMLEnabledMessage(builder.toString()), "Plugin Update Error", JOptionPane.DEFAULT_OPTION, - JOptionPane.ERROR_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO))); - } -} + if (isUpToDate) { + options = new String[2]; + options[0] = "Cancel"; + options[1] = "Select release"; -@SuppressWarnings("serial") -final class ContextMenu extends JPopupMenu { - private JMenuItem takeMeThere; - private JMenuItem openSpec; - private ActionListener menuListener; + initialSelection = options[1]; - public ContextMenu() { - - } - - public ContextMenu(String idModelElement) { - - menuListener = new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - switch (e.getActionCommand()) { - case "Take me there!": - System.out.println("Firing 'Highlight'"); - ViewUtils.highlightDiagramElement(idModelElement); - break; - case "Open Specification": - System.out.println("Firing 'Open Specification'"); - ViewUtils.openSpecDiagramElement(idModelElement); - break; - default: - break; - } - } - }; - - takeMeThere = new JMenuItem("Take me there!", new ImageIcon(ViewUtils.getFilePath(ViewUtils.NAVIGATION_LOGO))); - takeMeThere.addActionListener(menuListener); - openSpec = new JMenuItem("Open Specification", new ImageIcon(ViewUtils.getFilePath(ViewUtils.MORE_HORIZ_LOGO))); - openSpec.addActionListener(menuListener); - add(takeMeThere); - add(openSpec); - } + msg.append("Your plugin is up to date with the latest stable release."); + msg.append("\nIf you desire to install a different version of the plugin, click on \"Select release\"."); + msg.append("\nBe aware that \"alpha\" releases provide experimental new features that may not be fully integrated to the plugin."); + msg.append("\n\nThe procedure may take a couple of seconds."); + } else { + options = new String[3]; + options[0] = "Cancel"; + options[1] = "Select release"; + options[2] = "Install latest release"; + + initialSelection = options[2]; + + msg.append("The latest stable release of the plugin is the version " + lastestRelease.getTagName() + + "."); + msg.append( + "\nTo install this update, click on \"Install latest release\", or click on \"Select a release\" to install a different version."); + msg.append("\nBe aware that \"alpha\" releases are provide experimental new features that may present some issues."); + msg.append("\n\nThe procedure may take a couple of seconds."); + } - public void disableItem(String item) { - switch (item) { - case "Take me there!": - takeMeThere.setEnabled(false); - break; - case "Open Specification": - openSpec.setEnabled(false); - break; + final ViewManager vm = ApplicationManager.instance().getViewManager(); + int selectedOption = vm.showOptionDialog(vm.getRootFrame(), msg.toString(), "Plugin Update", + JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO)), + options, initialSelection); + + switch (selectedOption) { + case 2: + return lastestRelease; + case 1: + return selectReleaseToInstall(); default: - break; + return null; } } -} -final class ContextMenuListener extends MouseAdapter { - private ArrayList idModelElementList; - private JList messageList; + public static void updateSuccessDialog() { + final ViewManager vm = ApplicationManager.instance().getViewManager(); + final String msg = "Plugin successfully updated.\nPlease restart the application for the changes to take effect."; - ContextMenuListener(ArrayList list, JList messages) { - super(); - idModelElementList = list; - messageList = messages; + vm.showConfirmDialog(null, msg, "Plugin Update", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, + new ImageIcon(getFilePath(SIMPLE_LOGO))); } - @Override - public void mouseMoved(MouseEvent e) { - final Point p = e.getPoint(); - final int index = messageList.locationToIndex(p); + public static void updateErrorDialog() { + final ViewManager vm = ApplicationManager.instance().getViewManager(); + final StringBuilder builder = new StringBuilder(); + builder.append("Something went wrong during the update. Please verify your connection.
"); + builder.append("In case your plugin becomes unavailable, you may find instructions at " + OntoUMLPlugin.PLUGIN_REPO + ".
"); + builder.append("In this page you can also report this error and help us to improve our plugin."); - messageList.setSelectedIndex(index); + vm.showConfirmDialog(null, new HTMLEnabledMessage(builder.toString()), "Plugin Update Error", + JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, new ImageIcon(getFilePath(SIMPLE_LOGO))); } - @Override - public void mouseExited(MouseEvent e) { - messageList.clearSelection(); - } + public static GitHubRelease selectReleaseToInstall() { + final Map map = new HashMap<>(); + final Configurations config = Configurations.getInstance(); + final GitHubRelease installedRelease = config.getInstalledRelease(); + final String installedReleaseTagName = installedRelease != null + ? installedRelease.getTagName() : null; - public void mouseReleased(MouseEvent e) { - doPop(e); - } + config.getReleases().forEach(release -> { + String releaseTagName = release.getTagName(); - private void doPop(MouseEvent e) { - ContextMenu menu; - String idModelElement = idModelElementList.get(messageList.locationToIndex(e.getPoint())); + releaseTagName = installedReleaseTagName != null && releaseTagName.equals(installedReleaseTagName) + ? releaseTagName + " (installed version)" : releaseTagName; + + map.put(releaseTagName, release); + }); - if (idModelElement == null) { - menu = new ContextMenu(); - } else { - menu = new ContextMenu(idModelElement); - if (!ViewUtils.isElementInAnyDiagram(idModelElement)) { - menu.disableItem("Take me there!"); - } - } + ViewManager vm = ApplicationManager.instance().getViewManager(); + List keys = new ArrayList(map.keySet()); + keys.sort(Comparator.reverseOrder()); + Object[] keysArray = new String[keys.size()]; + keys.toArray(keysArray); + Object selectedValue = vm.showInputDialog(vm.getRootFrame(), + "Select the desired version of the OntoUML Plugin:", "Plugin Versions", JOptionPane.QUESTION_MESSAGE, + new ImageIcon(getFilePath(SIMPLE_LOGO)), keysArray, keysArray[0]); - menu.show(e.getComponent(), e.getX(), e.getY()); + return map.get(selectedValue); } -} \ No newline at end of file +} + diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/ConfigurationsView.java b/src/main/java/it/unibz/inf/ontouml/vp/views/ConfigurationsView.java index b827d57e..d3486a2d 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/ConfigurationsView.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/ConfigurationsView.java @@ -3,8 +3,8 @@ import com.vp.plugin.view.IDialog; import it.unibz.inf.ontouml.vp.OntoUMLPlugin; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.ProjectConfigurations; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.ProjectConfigurations; import javax.swing.*; import javax.swing.event.ChangeEvent; diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/ExportToGUFOView.java b/src/main/java/it/unibz/inf/ontouml/vp/views/GUFOExportView.java similarity index 92% rename from src/main/java/it/unibz/inf/ontouml/vp/views/ExportToGUFOView.java rename to src/main/java/it/unibz/inf/ontouml/vp/views/GUFOExportView.java index 5ba3e49b..d6dedca9 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/ExportToGUFOView.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/GUFOExportView.java @@ -31,17 +31,22 @@ import com.google.gson.JsonObject; import com.vp.plugin.ApplicationManager; import com.vp.plugin.diagram.IDiagramUIModel; +import com.vp.plugin.model.IAssociation; +import com.vp.plugin.model.IAssociationClass; +import com.vp.plugin.model.IAssociationEnd; +import com.vp.plugin.model.IAttribute; +import com.vp.plugin.model.IGeneralization; import com.vp.plugin.model.IModelElement; import com.vp.plugin.model.IProject; import com.vp.plugin.model.factory.IModelElementFactory; import com.vp.plugin.view.IDialog; import it.unibz.inf.ontouml.vp.OntoUMLPlugin; -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.ProjectConfigurations; -import it.unibz.inf.ontouml.vp.utils.ServerRequest; +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.model.ProjectConfigurations; +import it.unibz.inf.ontouml.vp.model.ServerRequest; -public class ExportToGUFOView extends JPanel { +public class GUFOExportView extends JPanel { private static final long serialVersionUID = 1L; private JTextField IRItxt; @@ -79,7 +84,7 @@ public class ExportToGUFOView extends JPanel { private IModelElement[] elementsMapping; private IModelElement[] packagesMapping; - public ExportToGUFOView(ProjectConfigurations configurations, ServerRequest request) { + public GUFOExportView(ProjectConfigurations configurations, ServerRequest request) { setSize(new Dimension(680, 550)); setLayout(new GridLayout(1, 1)); @@ -364,7 +369,7 @@ public ExportToGUFOView(ProjectConfigurations configurations, ServerRequest requ String[] nameElements = new String[elementsMapping.length]; for (int i = 0; i < elementsMapping.length; i++) - nameElements[i] = NameUtil.getDisplayName(elementsMapping[i]); + nameElements[i] = getDisplayName(elementsMapping[i]); namesBox = new JComboBox<>(nameElements); ((JLabel) namesBox.getRenderer()).setHorizontalAlignment(JLabel.LEFT); @@ -855,14 +860,6 @@ private void saveSelectedElements(String tree) { aux.add(((IDiagramUIModel) node.getUserObject()).getId()); } } - /* - * final IProject project = - * ApplicationManager.instance().getProjectManager().getProject(); final - * String[] datatypes = { IModelElementFactory.MODEL_TYPE_DATA_TYPE }; - * - * for (IModelElement datatype : project.toModelElementArray(datatypes)) - * aux.add(datatype.getId()); - */ } } @@ -969,6 +966,78 @@ public String getTablePackageMapping() { } + public static String getDisplayName(Object obj) { + if (obj == null) + return ""; + if (obj instanceof String) + return obj.toString(); + + if (obj instanceof IDiagramUIModel) { + IDiagramUIModel diagram = (IDiagramUIModel) obj; + + return diagram.getName() != null ? diagram.getName() : "Diagram"; + } + + if (obj instanceof IAttribute) { + IAttribute attribute = (IAttribute) obj; + + String attributeName = attribute.getName() != null ? attribute.getName() : ""; + + String attributeType = ""; + if (attribute.getType() != null) + attributeType = attribute.getTypeAsString(); + + return attributeName + " : " + attributeType; + } + + if (obj instanceof IAssociation) { + IAssociation association = (IAssociation) obj; + String assocName = ""; + + if (association.getName() != null && !association.getName().equals("")) + assocName = association.getName() + " "; + + String nameFrom = association.getFrom() == null ? "" : association.getFrom().getName(); + String nameTo = association.getTo() == null ? "" : association.getTo().getName(); + + return assocName + "(" + nameFrom + " -> " + nameTo + ")"; + } + + if (obj instanceof IAssociationEnd) { + IAssociationEnd assocEnd = (IAssociationEnd) obj; + + String endName = assocEnd.getName() != null ? assocEnd.getName() : ""; + String typeName = assocEnd.getType() != null ? assocEnd.getTypeAsString() : ""; + + return endName + " : " + typeName; + } + + if (obj instanceof IGeneralization) { + IGeneralization generalization = (IGeneralization) obj; + + String childTypeName = generalization.getTo() != null ? generalization.getTo().getName() : ""; + String parentTypeName = generalization.getFrom() != null ? generalization.getFrom().getName() : ""; + + return "(" + childTypeName + " -> " + parentTypeName + ")"; + } + + if (obj instanceof IAssociationClass) { + IAssociationClass assocClass = (IAssociationClass) obj; + + String nameFrom = assocClass.getFrom() != null ? assocClass.getFrom().getName() : ""; + String nameTo = assocClass.getTo() != null ? assocClass.getTo().getName() : ""; + + return "(" + nameFrom + " -> " + nameTo + ")"; + + } + + if (obj instanceof IModelElement) { + IModelElement element = (IModelElement) obj; + return element.getName() != null ? element.getName() : "ModelElement " + element.getId(); + } + + return "Element"; + } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/HTMLEnabledMessage.java b/src/main/java/it/unibz/inf/ontouml/vp/views/HTMLEnabledMessage.java index b435f443..2ea52a61 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/HTMLEnabledMessage.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/HTMLEnabledMessage.java @@ -3,14 +3,13 @@ import java.awt.Color; import java.awt.Desktop; import java.awt.Font; -import java.net.URI; import javax.swing.JEditorPane; import javax.swing.JLabel; import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; public class HTMLEnabledMessage extends JEditorPane { private static final long serialVersionUID = 1L; @@ -25,13 +24,13 @@ public void hyperlinkUpdate(HyperlinkEvent e) { final Desktop desktop = Desktop.getDesktop(); desktop.browse(e.getURL().toURI()); } catch (UnsupportedOperationException unsupportedException) { - ViewUtils.reportBugErrorDialog(true); + ViewManagerUtils.reportBugErrorDialog(true); unsupportedException.printStackTrace(); } catch (SecurityException securityException) { - ViewUtils.reportBugErrorDialog(true); + ViewManagerUtils.reportBugErrorDialog(true); securityException.printStackTrace(); } catch(Exception exception) { - ViewUtils.reportBugErrorDialog(false); + ViewManagerUtils.reportBugErrorDialog(false); exception.printStackTrace(); } } diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/IssueLogMenu.java b/src/main/java/it/unibz/inf/ontouml/vp/views/IssueLogMenu.java new file mode 100644 index 00000000..b721214a --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/IssueLogMenu.java @@ -0,0 +1,60 @@ +package it.unibz.inf.ontouml.vp.views; + +import javax.swing.*; + +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +@SuppressWarnings("serial") +public final class IssueLogMenu extends JPopupMenu { + private JMenuItem takeMeThere; + private JMenuItem openSpec; + private ActionListener menuListener; + + public IssueLogMenu() { + + } + + public IssueLogMenu(String idModelElement) { + + menuListener = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + switch (e.getActionCommand()) { + case "Take me there!": + System.out.println("Firing 'Highlight'"); + ViewManagerUtils.highlightDiagramElement(idModelElement); + break; + case "Open Specification": + System.out.println("Firing 'Open Specification'"); + ViewManagerUtils.openSpecDiagramElement(idModelElement); + break; + default: + break; + } + } + }; + + takeMeThere = new JMenuItem("Take me there!", new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.NAVIGATION_LOGO))); + takeMeThere.addActionListener(menuListener); + openSpec = new JMenuItem("Open Specification", new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.MORE_HORIZ_LOGO))); + openSpec.addActionListener(menuListener); + add(takeMeThere); + add(openSpec); + } + + public void disableItem(String item) { + switch (item) { + case "Take me there!": + takeMeThere.setEnabled(false); + break; + case "Open Specification": + openSpec.setEnabled(false); + break; + default: + break; + } + } +} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/JCheckBoxTree.java b/src/main/java/it/unibz/inf/ontouml/vp/views/JCheckBoxTree.java index a1185bb6..32377a0c 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/JCheckBoxTree.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/JCheckBoxTree.java @@ -44,919 +44,922 @@ import com.vp.plugin.model.IProject; import com.vp.plugin.model.factory.IModelElementFactory; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; public class JCheckBoxTree extends JTree { - private static final long serialVersionUID = -4194122328392241790L; - - JCheckBoxTree selfPointer = this; - - // Defining data structure that will enable to fast check-indicate the state of - // each node - // It totally replaces the "selection" mechanism of the JTree - private class CheckedNode { - boolean isSelected; - boolean hasChildren; - boolean allChildrenSelected; - - public CheckedNode(boolean isSelected_, boolean hasChildren_, boolean allChildrenSelected_) { - isSelected = isSelected_; - hasChildren = hasChildren_; - allChildrenSelected = allChildrenSelected_; - } - } - - HashMap nodesCheckingState; - HashSet checkedPaths = new HashSet(); - - // Defining a new event type for the checking mechanism and preparing - // event-handling mechanism - protected EventListenerList listenerList = new EventListenerList(); - - public class CheckChangeEvent extends EventObject { - private static final long serialVersionUID = -8100230309044193368L; - - public CheckChangeEvent(Object source) { - super(source); - } - } - - public interface CheckChangeEventListener extends EventListener { - public void checkStateChanged(CheckChangeEvent event); - } - - public void addCheckChangeEventListener(CheckChangeEventListener listener) { - listenerList.add(CheckChangeEventListener.class, listener); - } - - public void removeCheckChangeEventListener(CheckChangeEventListener listener) { - listenerList.remove(CheckChangeEventListener.class, listener); - } - - void fireCheckChangeEvent(CheckChangeEvent evt) { - Object[] listeners = listenerList.getListenerList(); - for (int i = 0; i < listeners.length; i++) { - if (listeners[i] == CheckChangeEventListener.class) { - ((CheckChangeEventListener) listeners[i + 1]).checkStateChanged(evt); - } - } - } - - // Override - public void setModel(TreeModel newModel) { - super.setModel(newModel); - resetCheckingState(); - } - - // New method that returns only the checked paths (totally ignores original - // "selection" mechanism) - public TreePath[] getCheckedPaths() { - return checkedPaths.toArray(new TreePath[checkedPaths.size()]); - } - - // Returns true in case that the node is selected, has children but not all of - // them are selected - public boolean isSelectedPartially(TreePath path) { - CheckedNode cn = nodesCheckingState.get(path); - return cn.isSelected && cn.hasChildren && !cn.allChildrenSelected; - } - - private void resetCheckingState() { - nodesCheckingState = new HashMap(); - checkedPaths = new HashSet(); - ElementNode node = (ElementNode) getModel().getRoot(); - if (node == null) { - return; - } - addSubtreeToCheckingStateTracking(node); - } - - // Creating data structure of the current model for the checking mechanism - private void addSubtreeToCheckingStateTracking(ElementNode node) { - TreeNode[] path = node.getPath(); - TreePath tp = new TreePath(path); - CheckedNode cn = new CheckedNode(false, node.getChildCount() > 0, false); - nodesCheckingState.put(tp, cn); - for (int i = 0; i < node.getChildCount(); i++) { - addSubtreeToCheckingStateTracking( - (ElementNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent()); - } - } - - // Overriding cell renderer by a class that ignores the original "selection" - // mechanism - // It decides how to show the nodes due to the checking-mechanism - private class CheckBoxCellRenderer extends JPanel implements TreeCellRenderer { - private static final long serialVersionUID = -7341833835878991719L; - JCheckBox checkBox; - JLabel label; - - public CheckBoxCellRenderer() { - super(); - this.setLayout(new BorderLayout()); - checkBox = new JCheckBox(); - label = new JLabel(); - add(label, BorderLayout.WEST); - add(checkBox, BorderLayout.CENTER); - setOpaque(false); - } - - @Override - public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, - boolean leaf, int row, boolean hasFocus) { - ElementNode node = (ElementNode) value; - Object obj = node.getUserObject(); - TreePath tp = new TreePath(node.getPath()); - CheckedNode cn = nodesCheckingState.get(tp); - - if (cn == null) { - return this; - } - - if (obj instanceof IDiagramUIModel) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.DIAGRAM_LOGO))); - else if (obj instanceof IClass) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.CLASS_LOGO))); - else if (obj instanceof IDataType) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.DATATYPE_LOGO))); - else if (obj instanceof IAttribute) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.ATTRIBUTE_LOGO))); - else if (obj instanceof IAssociation) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.ASSOCIATION_LOGO))); - else if (obj instanceof IAssociationEnd) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.ATTRIBUTE_LOGO))); - else if (obj instanceof IGeneralization) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.GENERALIZATION_LOGO))); - else if (obj instanceof IGeneralizationSet) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.GENERALIZATION_SET_LOGO))); - else if (obj instanceof IAssociationClass) - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.ASSOCIATION_LOGO))); - else - label.setIcon(new ImageIcon(ViewUtils.getFilePath(ViewUtils.PACKAGE_LOGO))); - - checkBox.setSelected(cn.isSelected); - checkBox.setText(getNameNode(node)); - - checkBox.setOpaque(cn.isSelected && cn.hasChildren && !cn.allChildrenSelected); - - return this; - } - - } - - private String getNameNode(ElementNode node) { - return NameUtil.getDisplayName(node.getUserObject()); + private static final long serialVersionUID = -4194122328392241790L; + + JCheckBoxTree selfPointer = this; + + // Defining data structure that will enable to fast check-indicate the state of + // each node + // It totally replaces the "selection" mechanism of the JTree + private class CheckedNode { + boolean isSelected; + boolean hasChildren; + boolean allChildrenSelected; + + public CheckedNode(boolean isSelected_, boolean hasChildren_, boolean allChildrenSelected_) { + isSelected = isSelected_; + hasChildren = hasChildren_; + allChildrenSelected = allChildrenSelected_; + } + } + + HashMap nodesCheckingState; + HashSet checkedPaths = new HashSet(); + + // Defining a new event type for the checking mechanism and preparing + // event-handling mechanism + protected EventListenerList listenerList = new EventListenerList(); + + public class CheckChangeEvent extends EventObject { + private static final long serialVersionUID = -8100230309044193368L; + + public CheckChangeEvent(Object source) { + super(source); + } + } + + public interface CheckChangeEventListener extends EventListener { + public void checkStateChanged(CheckChangeEvent event); + } + + public void addCheckChangeEventListener(CheckChangeEventListener listener) { + listenerList.add(CheckChangeEventListener.class, listener); + } + + public void removeCheckChangeEventListener(CheckChangeEventListener listener) { + listenerList.remove(CheckChangeEventListener.class, listener); + } + + void fireCheckChangeEvent(CheckChangeEvent evt) { + Object[] listeners = listenerList.getListenerList(); + for (int i = 0; i < listeners.length; i++) { + if (listeners[i] == CheckChangeEventListener.class) { + ((CheckChangeEventListener) listeners[i + 1]).checkStateChanged(evt); + } + } + } + + // Override + public void setModel(TreeModel newModel) { + super.setModel(newModel); + resetCheckingState(); + } + + // New method that returns only the checked paths (totally ignores original + // "selection" mechanism) + public TreePath[] getCheckedPaths() { + return checkedPaths.toArray(new TreePath[checkedPaths.size()]); + } + + // Returns true in case that the node is selected, has children but not all of + // them are selected + public boolean isSelectedPartially(TreePath path) { + CheckedNode cn = nodesCheckingState.get(path); + return cn.isSelected && cn.hasChildren && !cn.allChildrenSelected; + } + + private void resetCheckingState() { + nodesCheckingState = new HashMap(); + checkedPaths = new HashSet(); + ElementNode node = (ElementNode) getModel().getRoot(); + if (node == null) { + return; + } + addSubtreeToCheckingStateTracking(node); + } + + // Creating data structure of the current model for the checking mechanism + private void addSubtreeToCheckingStateTracking(ElementNode node) { + TreeNode[] path = node.getPath(); + TreePath tp = new TreePath(path); + CheckedNode cn = new CheckedNode(false, node.getChildCount() > 0, false); + nodesCheckingState.put(tp, cn); + for (int i = 0; i < node.getChildCount(); i++) { + addSubtreeToCheckingStateTracking( + (ElementNode) tp.pathByAddingChild(node.getChildAt(i)).getLastPathComponent()); + } + } + + // Overriding cell renderer by a class that ignores the original "selection" + // mechanism + // It decides how to show the nodes due to the checking-mechanism + private class CheckBoxCellRenderer extends JPanel implements TreeCellRenderer { + private static final long serialVersionUID = -7341833835878991719L; + JCheckBox checkBox; + JLabel label; + + public CheckBoxCellRenderer() { + super(); + this.setLayout(new BorderLayout()); + checkBox = new JCheckBox(); + label = new JLabel(); + add(label, BorderLayout.WEST); + add(checkBox, BorderLayout.CENTER); + setOpaque(false); + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, + boolean leaf, int row, boolean hasFocus) { + ElementNode node = (ElementNode) value; + Object obj = node.getUserObject(); + TreePath tp = new TreePath(node.getPath()); + CheckedNode cn = nodesCheckingState.get(tp); + + if (cn == null) { + return this; + } + + if (obj instanceof IDiagramUIModel) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.DIAGRAM_LOGO))); + else if (obj instanceof IClass) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.CLASS_LOGO))); + else if (obj instanceof IDataType) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.DATATYPE_LOGO))); + else if (obj instanceof IAttribute) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.ATTRIBUTE_LOGO))); + else if (obj instanceof IAssociation) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.ASSOCIATION_LOGO))); + else if (obj instanceof IAssociationEnd) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.ATTRIBUTE_LOGO))); + else if (obj instanceof IGeneralization) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.GENERALIZATION_LOGO))); + else if (obj instanceof IGeneralizationSet) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.GENERALIZATION_SET_LOGO))); + else if (obj instanceof IAssociationClass) + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.ASSOCIATION_LOGO))); + else + label.setIcon(new ImageIcon(ViewManagerUtils.getFilePath(ViewManagerUtils.PACKAGE_LOGO))); + + checkBox.setSelected(cn.isSelected); + checkBox.setText(getNameNode(node)); + + checkBox.setOpaque(cn.isSelected && cn.hasChildren && !cn.allChildrenSelected); + + return this; + } + + } + + private String getNameNode(ElementNode node) { + return GUFOExportView.getDisplayName(node.getUserObject()); + } + + public JCheckBoxTree(String type) { + + super(getTreeModel(type)); + // Disabling toggling by double-click + this.setToggleClickCount(0); + // Overriding cell renderer by new one defined above + CheckBoxCellRenderer cellRenderer = new CheckBoxCellRenderer(); + this.setCellRenderer(cellRenderer); + + DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel() { + private static final long serialVersionUID = -8190634240451667286L; + + public void setSelectionPath(TreePath path) { + boolean checkMode = !nodesCheckingState.get(path).isSelected; + checkSubTree(path, checkMode); + updatePredecessorsWithCheckMode(path, checkMode); + // Firing the check change event + fireCheckChangeEvent(new CheckChangeEvent(new Object())); + // Repainting tree after the data structures were updated + findSimilarNodes((ElementNode) path.getLastPathComponent()); + + selectTypeNodes((ElementNode) path.getLastPathComponent()); + + if (((ElementNode) path.getLastPathComponent()).getUserObject() instanceof IGeneralizationSet) + selectAllGeneralizationsFromSet((ElementNode) path.getLastPathComponent(), checkMode); + + selfPointer.repaint(); + } + + public void addSelectionPath(TreePath path) { + } + + public void removeSelectionPath(TreePath path) { + } + + public void setSelectionPaths(TreePath[] pPaths) { + } + }; + + this.setSelectionModel(dtsm); + } + + @SuppressWarnings("unchecked") + private void visitAllNodesAndCheckSimilar(ElementNode root, ElementNode nodeToCompare) { + + // if same Object + if (((ElementNode) root).getUserObject().equals(nodeToCompare.getUserObject())) { + + TreeNode[] old_treeNode = nodeToCompare.getPath(); + TreePath oldTp = new TreePath(old_treeNode); + + TreeNode[] new_treeNode = root.getPath(); + TreePath newTp = new TreePath(new_treeNode); + + // if different paths + if (!oldTp.toString().equals(newTp.toString())) { + + boolean checkMode = nodesCheckingState.get(oldTp).isSelected; + + CheckedNode cn = nodesCheckingState.get(newTp); + cn.isSelected = checkMode; + + if (checkMode) + checkedPaths.add(newTp); + else + checkedPaths.remove(newTp); + } + + } + + if (root.getChildCount() >= 0) { + for (Enumeration e = root.children(); e.hasMoreElements();) { + ElementNode n = (ElementNode) e.nextElement(); + + visitAllNodesAndCheckSimilar(n, nodeToCompare); + } + } } - public JCheckBoxTree(String type) { + @SuppressWarnings("unchecked") + private void visitAllAndCheckSameId(ElementNode root, String id, boolean checkMode) { - super(getTreeModel(type)); - // Disabling toggling by double-click - this.setToggleClickCount(0); - // Overriding cell renderer by new one defined above - CheckBoxCellRenderer cellRenderer = new CheckBoxCellRenderer(); - this.setCellRenderer(cellRenderer); + if (root.getUserObject() instanceof IModelElement) { + IModelElement rootModelElement = ((IModelElement) ((DefaultMutableTreeNode) root).getUserObject()); - DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel() { - private static final long serialVersionUID = -8190634240451667286L; + // if same Object + if (rootModelElement.getId().equals(id)) { - public void setSelectionPath(TreePath path) { - boolean checkMode = !nodesCheckingState.get(path).isSelected; - checkSubTree(path, checkMode); - updatePredecessorsWithCheckMode(path, checkMode); - // Firing the check change event - fireCheckChangeEvent(new CheckChangeEvent(new Object())); - // Repainting tree after the data structures were updated - findSimilarNodes((ElementNode) path.getLastPathComponent()); + TreeNode[] new_treeNode = root.getPath(); + TreePath newTp = new TreePath(new_treeNode); - selectTypeNodes((ElementNode) path.getLastPathComponent()); + CheckedNode cn = nodesCheckingState.get(newTp); + cn.isSelected = checkMode; - if (((ElementNode) path.getLastPathComponent()).getUserObject() instanceof IGeneralizationSet) - selectAllGeneralizationsFromSet((ElementNode) path.getLastPathComponent(), checkMode); + if (checkMode) + checkedPaths.add(newTp); + else + checkedPaths.remove(newTp); - selfPointer.repaint(); - } + } + } - public void addSelectionPath(TreePath path) { - } + if (root.getChildCount() >= 0) { + for (Enumeration e = root.children(); e.hasMoreElements();) { + ElementNode n = (ElementNode) e.nextElement(); - public void removeSelectionPath(TreePath path) { - } + visitAllAndCheckSameId(n, id, checkMode); + } + } + } - public void setSelectionPaths(TreePath[] pPaths) { - } - }; + protected void findSimilarNodes(ElementNode node) { - this.setSelectionModel(dtsm); - } + for (int i = 0; i < node.getChildCount(); i++) + findSimilarNodes((ElementNode) node.getChildAt(i)); - private void visitAllNodesAndCheckSimilar(ElementNode root, ElementNode nodeToCompare) { + ElementNode root = (ElementNode) this.getModel().getRoot(); + visitAllNodesAndCheckSimilar(root, node); + } - // if same Object - if (((ElementNode) root).getUserObject().equals(nodeToCompare.getUserObject())) { + @SuppressWarnings("unchecked") + private void visitAllNodesAndCheckType(ElementNode root, ElementNode nodeToCompare) { + String typeOriginal = ""; + String typeCurrentNode = ""; - TreeNode[] old_treeNode = nodeToCompare.getPath(); - TreePath oldTp = new TreePath(old_treeNode); + if (nodeToCompare.getUserObject() instanceof IClass) + typeOriginal = ((IClass) nodeToCompare.getUserObject()).getName(); - TreeNode[] new_treeNode = root.getPath(); - TreePath newTp = new TreePath(new_treeNode); + if (nodeToCompare.getUserObject() instanceof IAttribute) + typeOriginal = ((IAttribute) nodeToCompare.getUserObject()).getTypeAsString(); - // if different paths - if (!oldTp.toString().equals(newTp.toString())) { + if (root.getUserObject() instanceof IClass) + typeCurrentNode = ((IClass) root.getUserObject()).getName(); - boolean checkMode = nodesCheckingState.get(oldTp).isSelected; + if (root.getUserObject() instanceof IDataType) + typeCurrentNode = ((IDataType) root.getUserObject()).getName(); - CheckedNode cn = nodesCheckingState.get(newTp); - cn.isSelected = checkMode; + if (typeOriginal != null && typeCurrentNode.contentEquals(typeOriginal)) { - if (checkMode) - checkedPaths.add(newTp); - else - checkedPaths.remove(newTp); - } + TreeNode[] old_treeNode = nodeToCompare.getPath(); + TreePath oldTp = new TreePath(old_treeNode); - } + TreeNode[] new_treeNode = root.getPath(); + TreePath newTp = new TreePath(new_treeNode); - if (root.getChildCount() >= 0) { - for (Enumeration e = root.children(); e.hasMoreElements(); ) { - ElementNode n = (ElementNode) e.nextElement(); + // if different paths + if (!oldTp.toString().equals(newTp.toString())) { + boolean checkMode = nodesCheckingState.get(oldTp).isSelected; - visitAllNodesAndCheckSimilar(n, nodeToCompare); - } - } - } + if ((root.getUserObject() instanceof IClass || root.getUserObject() instanceof IDataType) + && checkMode == true) { - private void visitAllAndCheckSameId(ElementNode root, String id, boolean checkMode) { + CheckedNode cn = nodesCheckingState.get(newTp); + cn.isSelected = checkMode; - if (root.getUserObject() instanceof IModelElement) { - IModelElement rootModelElement = ((IModelElement) ((DefaultMutableTreeNode) root).getUserObject()); + if (checkMode) + checkedPaths.add(newTp); + else + checkedPaths.remove(newTp); + } - // if same Object - if (rootModelElement.getId().equals(id)) { + } + } - TreeNode[] new_treeNode = root.getPath(); - TreePath newTp = new TreePath(new_treeNode); + if (root.getChildCount() >= 0) { + for (Enumeration e = root.children(); e.hasMoreElements();) { + ElementNode n = (ElementNode) e.nextElement(); - CheckedNode cn = nodesCheckingState.get(newTp); - cn.isSelected = checkMode; + visitAllNodesAndCheckType(n, nodeToCompare); + } + } + } - if (checkMode) - checkedPaths.add(newTp); - else - checkedPaths.remove(newTp); + protected void selectTypeNodes(ElementNode node) { + ElementNode root = (ElementNode) this.getModel().getRoot(); + visitAllNodesAndCheckType(root, node); + } - } - } + protected void selectAllGeneralizationsFromSet(ElementNode node, boolean checkMode) { - if (root.getChildCount() >= 0) { - for (Enumeration e = root.children(); e.hasMoreElements(); ) { - ElementNode n = (ElementNode) e.nextElement(); + if (!(node.getUserObject() instanceof IGeneralizationSet)) + return; - visitAllAndCheckSameId(n, id, checkMode); - } - } - } + IGeneralizationSet gSet = ((IGeneralizationSet) ((DefaultMutableTreeNode) node).getUserObject()); - protected void findSimilarNodes(ElementNode node) { + IGeneralization[] generalizations = gSet.toGeneralizationArray(); - for (int i = 0; i < node.getChildCount(); i++) - findSimilarNodes((ElementNode) node.getChildAt(i)); + if (generalizations == null) + return; - ElementNode root = (ElementNode) this.getModel().getRoot(); - visitAllNodesAndCheckSimilar(root, node); - } + ElementNode root = (ElementNode) this.getModel().getRoot(); - private void visitAllNodesAndCheckType(ElementNode root, ElementNode nodeToCompare) { - String typeOriginal = ""; - String typeCurrentNode = ""; + for (int i = 0; i < generalizations.length; i++) { + visitAllAndCheckSameId(root, generalizations[i].getId(), checkMode); + } - if (nodeToCompare.getUserObject() instanceof IClass) - typeOriginal = ((IClass) nodeToCompare.getUserObject()).getName(); + } - if (nodeToCompare.getUserObject() instanceof IAttribute) - typeOriginal = ((IAttribute) nodeToCompare.getUserObject()).getTypeAsString(); + // When a node is checked/unchecked, updating the states of the predecessors + protected void updatePredecessorsWithCheckMode(TreePath tp, boolean check) { + TreePath parentPath = tp.getParentPath(); + // If it is the root, stop the recursive calls and return + if (parentPath == null) + return; + + CheckedNode currentNode = nodesCheckingState.get(tp); + // It is allowed to choose a class without its attributes + if (((ElementNode) tp.getLastPathComponent()).getUserObject() instanceof IAttribute + && currentNode.isSelected == false) + return; + + CheckedNode parentCheckedNode = nodesCheckingState.get(parentPath); + ElementNode parentNode = (ElementNode) parentPath.getLastPathComponent(); + parentCheckedNode.allChildrenSelected = true; + parentCheckedNode.isSelected = false; + for (int i = 0; i < parentNode.getChildCount(); i++) { + TreePath childPath = parentPath.pathByAddingChild(parentNode.getChildAt(i)); + CheckedNode childCheckedNode = nodesCheckingState.get(childPath); + // It is enough that even one subtree is not fully selected + // to determine that the parent is not fully selected + if (!childCheckedNode.allChildrenSelected) { + parentCheckedNode.allChildrenSelected = false; + } + // If at least one child is selected, selecting also the parent + if (childCheckedNode.isSelected) { + parentCheckedNode.isSelected = true; + } + } + if (parentCheckedNode.isSelected) { + checkedPaths.add(parentPath); + } else { + checkedPaths.remove(parentPath); + } + // Go to upper predecessor + updatePredecessorsWithCheckMode(parentPath, check); + } - if (root.getUserObject() instanceof IClass) - typeCurrentNode = ((IClass) root.getUserObject()).getName(); + // Recursively checks/unchecks a subtree + protected void checkSubTree(TreePath tp, boolean check) { + CheckedNode cn = nodesCheckingState.get(tp); + cn.isSelected = check; + ElementNode node = (ElementNode) tp.getLastPathComponent(); + selectTypeNodes(node); + for (int i = 0; i < node.getChildCount(); i++) { + checkSubTree(tp.pathByAddingChild(node.getChildAt(i)), check); + } + cn.allChildrenSelected = check; + if (check) { + checkedPaths.add(tp); + } else { + checkedPaths.remove(tp); + } + } - if (root.getUserObject() instanceof IDataType) - typeCurrentNode = ((IDataType) root.getUserObject()).getName(); + private static TreeModel getTreeModel(String type) { + if (type.equals("package")) + return getTreeModelPackage(); + else + return getTreeModelDiagram(); + } - if (typeOriginal != null && typeCurrentNode.contentEquals(typeOriginal)) { + private static TreeModel getTreeModelPackage() { + final IProject project = ApplicationManager.instance().getProjectManager().getProject(); + final String[] rootLevelElements = { IModelElementFactory.MODEL_TYPE_PACKAGE, + IModelElementFactory.MODEL_TYPE_MODEL, IModelElementFactory.MODEL_TYPE_CLASS, + IModelElementFactory.MODEL_TYPE_DATA_TYPE }; + final String[] anyLevelElements = { IModelElementFactory.MODEL_TYPE_GENERALIZATION, + IModelElementFactory.MODEL_TYPE_ASSOCIATION, IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS }; - TreeNode[] old_treeNode = nodeToCompare.getPath(); - TreePath oldTp = new TreePath(old_treeNode); + ElementNode root = new ElementNode("All Models"); - TreeNode[] new_treeNode = root.getPath(); - TreePath newTp = new TreePath(new_treeNode); + for (IModelElement rootElement : project.toModelElementArray(rootLevelElements)) + setChildrenRecursively(rootElement, root); - // if different paths - if (!oldTp.toString().equals(newTp.toString())) { - boolean checkMode = nodesCheckingState.get(oldTp).isSelected; - - if ((root.getUserObject() instanceof IClass || root.getUserObject() instanceof IDataType) - && checkMode == true) { - - CheckedNode cn = nodesCheckingState.get(newTp); - cn.isSelected = checkMode; - - if (checkMode) - checkedPaths.add(newTp); - else - checkedPaths.remove(newTp); - } - - } - } - - if (root.getChildCount() >= 0) { - for (Enumeration e = root.children(); e.hasMoreElements(); ) { - ElementNode n = (ElementNode) e.nextElement(); - - visitAllNodesAndCheckType(n, nodeToCompare); - } - } - } - - protected void selectTypeNodes(ElementNode node) { - ElementNode root = (ElementNode) this.getModel().getRoot(); - visitAllNodesAndCheckType(root, node); - } - - protected void selectAllGeneralizationsFromSet(ElementNode node, boolean checkMode) { - - if (!(node.getUserObject() instanceof IGeneralizationSet)) - return; - - IGeneralizationSet gSet = ((IGeneralizationSet) ((DefaultMutableTreeNode) node).getUserObject()); - - IGeneralization[] generalizations = gSet.toGeneralizationArray(); - - if (generalizations == null) - return; - - ElementNode root = (ElementNode) this.getModel().getRoot(); - - for (int i = 0; i < generalizations.length; i++) { - visitAllAndCheckSameId(root, generalizations[i].getId(), checkMode); - } - - } - - // When a node is checked/unchecked, updating the states of the predecessors - protected void updatePredecessorsWithCheckMode(TreePath tp, boolean check) { - TreePath parentPath = tp.getParentPath(); - // If it is the root, stop the recursive calls and return - if (parentPath == null) - return; - - CheckedNode currentNode = nodesCheckingState.get(tp); - // It is allowed to choose a class without its attributes - if (((ElementNode) tp.getLastPathComponent()).getUserObject() instanceof IAttribute - && currentNode.isSelected == false) - return; - - CheckedNode parentCheckedNode = nodesCheckingState.get(parentPath); - ElementNode parentNode = (ElementNode) parentPath.getLastPathComponent(); - parentCheckedNode.allChildrenSelected = true; - parentCheckedNode.isSelected = false; - for (int i = 0; i < parentNode.getChildCount(); i++) { - TreePath childPath = parentPath.pathByAddingChild(parentNode.getChildAt(i)); - CheckedNode childCheckedNode = nodesCheckingState.get(childPath); - // It is enough that even one subtree is not fully selected - // to determine that the parent is not fully selected - if (!childCheckedNode.allChildrenSelected) { - parentCheckedNode.allChildrenSelected = false; - } - // If at least one child is selected, selecting also the parent - if (childCheckedNode.isSelected) { - parentCheckedNode.isSelected = true; - } - } - if (parentCheckedNode.isSelected) { - checkedPaths.add(parentPath); - } else { - checkedPaths.remove(parentPath); - } - // Go to upper predecessor - updatePredecessorsWithCheckMode(parentPath, check); - } - - // Recursively checks/unchecks a subtree - protected void checkSubTree(TreePath tp, boolean check) { - CheckedNode cn = nodesCheckingState.get(tp); - cn.isSelected = check; - ElementNode node = (ElementNode) tp.getLastPathComponent(); - selectTypeNodes(node); - for (int i = 0; i < node.getChildCount(); i++) { - checkSubTree(tp.pathByAddingChild(node.getChildAt(i)), check); - } - cn.allChildrenSelected = check; - if (check) { - checkedPaths.add(tp); - } else { - checkedPaths.remove(tp); - } - } - - private static TreeModel getTreeModel(String type) { - if (type.equals("package")) - return getTreeModelPackage(); - else - return getTreeModelDiagram(); - } - - private static TreeModel getTreeModelPackage() { - final IProject project = ApplicationManager.instance().getProjectManager().getProject(); - final String[] rootLevelElements = {IModelElementFactory.MODEL_TYPE_PACKAGE, - IModelElementFactory.MODEL_TYPE_MODEL, IModelElementFactory.MODEL_TYPE_CLASS, - IModelElementFactory.MODEL_TYPE_DATA_TYPE}; - final String[] anyLevelElements = {IModelElementFactory.MODEL_TYPE_GENERALIZATION, - IModelElementFactory.MODEL_TYPE_ASSOCIATION, IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS}; - - ElementNode root = new ElementNode("All Models"); - - for (IModelElement rootElement : project.toModelElementArray(rootLevelElements)) - setChildrenRecursively(rootElement, root); - - for (IModelElement rootElement : project.toAllLevelModelElementArray(anyLevelElements)) - setChildrenRecursively(rootElement, root); - - return new DefaultTreeModel(root); - } - - private static TreeModel getTreeModelDiagram() { - final IDiagramUIModel[] diagramArray = ApplicationManager.instance().getProjectManager().getProject() - .toDiagramArray(); - - ElementNode root = new ElementNode("All Diagrams"); - - if (diagramArray != null) { - - for (IDiagramUIModel diagram : diagramArray) { - - if (diagram instanceof IClassDiagramUIModel) { - ElementNode parent; - parent = new ElementNode(diagram); - root.add(parent); - setChildrenFromDiagrams(diagram, parent); - } - } - } - - final IProject project = ApplicationManager.instance().getProjectManager().getProject(); - final String[] datatypes = {IModelElementFactory.MODEL_TYPE_DATA_TYPE}; - - for (IModelElement datatype : project.toModelElementArray(datatypes)) { - ElementNode datatypeNodes = new ElementNode(datatype); - root.add(datatypeNodes); - } - - return new DefaultTreeModel(root); - } - - private static ElementNode setChildrenRecursively(IModelElement modelElement, ElementNode parent) { - ElementNode newRoot = parent; - - final String[] rootLevelElements = {IModelElementFactory.MODEL_TYPE_PACKAGE, - IModelElementFactory.MODEL_TYPE_MODEL, IModelElementFactory.MODEL_TYPE_CLASS, - IModelElementFactory.MODEL_TYPE_ASSOCIATION, IModelElementFactory.MODEL_TYPE_DATA_TYPE, - IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET, IModelElementFactory.MODEL_TYPE_GENERALIZATION}; - - if (modelElement instanceof IModel) { - IModel model = (IModel) modelElement; - - ElementNode newParent; - newParent = new ElementNode(model); - - newRoot.add(newParent); - - for (IModelElement element : model.toChildArray(rootLevelElements)) - setChildrenRecursively(element, newParent); - } + for (IModelElement rootElement : project.toAllLevelModelElementArray(anyLevelElements)) + setChildrenRecursively(rootElement, root); - if (modelElement instanceof IPackage) { - IPackage pckg = (IPackage) modelElement; + return new DefaultTreeModel(root); + } + + private static TreeModel getTreeModelDiagram() { + final IDiagramUIModel[] diagramArray = ApplicationManager.instance().getProjectManager().getProject() + .toDiagramArray(); - ElementNode newParent; - newParent = new ElementNode(pckg); + ElementNode root = new ElementNode("All Diagrams"); - newRoot.add(newParent); + if (diagramArray != null) { - for (IModelElement element : pckg.toChildArray(rootLevelElements)) - setChildrenRecursively(element, newParent); - } + for (IDiagramUIModel diagram : diagramArray) { - if (modelElement instanceof IClass) { - IClass _class = (IClass) modelElement; - ElementNode newParent; + if (diagram instanceof IClassDiagramUIModel) { + ElementNode parent; + parent = new ElementNode(diagram); + root.add(parent); + setChildrenFromDiagrams(diagram, parent); + } + } + } - newParent = new ElementNode(_class); + final IProject project = ApplicationManager.instance().getProjectManager().getProject(); + final String[] datatypes = { IModelElementFactory.MODEL_TYPE_DATA_TYPE }; - IAttribute[] attributes = _class.toAttributeArray(); + for (IModelElement datatype : project.toModelElementArray(datatypes)) { + ElementNode datatypeNodes = new ElementNode(datatype); + root.add(datatypeNodes); + } - for (int j = 0; attributes != null && j < attributes.length; j++) - newParent.add(new ElementNode(attributes[j])); + return new DefaultTreeModel(root); + } - newRoot.add(newParent); - } + private static ElementNode setChildrenRecursively(IModelElement modelElement, ElementNode parent) { + ElementNode newRoot = parent; - if (modelElement instanceof IAssociation) { - IAssociation association = (IAssociation) modelElement; - ElementNode newParent; + final String[] rootLevelElements = { IModelElementFactory.MODEL_TYPE_PACKAGE, + IModelElementFactory.MODEL_TYPE_MODEL, IModelElementFactory.MODEL_TYPE_CLASS, + IModelElementFactory.MODEL_TYPE_ASSOCIATION, IModelElementFactory.MODEL_TYPE_DATA_TYPE, + IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET, IModelElementFactory.MODEL_TYPE_GENERALIZATION }; - newParent = new ElementNode(association); + if (modelElement instanceof IModel) { + IModel model = (IModel) modelElement; - IAssociationEnd fromEnd = (IAssociationEnd) association.getFromEnd(); - IAssociationEnd toEnd = (IAssociationEnd) association.getToEnd(); + ElementNode newParent; + newParent = new ElementNode(model); - if (fromEnd != null) - newParent.add(new ElementNode(fromEnd)); + newRoot.add(newParent); - if (toEnd != null) - newParent.add(new ElementNode(toEnd)); + for (IModelElement element : model.toChildArray(rootLevelElements)) + setChildrenRecursively(element, newParent); + } - newRoot.add(newParent); - } + if (modelElement instanceof IPackage) { + IPackage pckg = (IPackage) modelElement; - if (modelElement instanceof IDataType) { - IDataType _class = (IDataType) modelElement; + ElementNode newParent; + newParent = new ElementNode(pckg); - ElementNode newParent; - newParent = new ElementNode(_class); + newRoot.add(newParent); - newRoot.add(newParent); - } + for (IModelElement element : pckg.toChildArray(rootLevelElements)) + setChildrenRecursively(element, newParent); + } - if (modelElement instanceof IGeneralizationSet) { - IGeneralizationSet generalizationSet = (IGeneralizationSet) modelElement; - ElementNode newParent; + if (modelElement instanceof IClass) { + IClass _class = (IClass) modelElement; + ElementNode newParent; - newParent = new ElementNode(generalizationSet); - newRoot.add(newParent); - } + newParent = new ElementNode(_class); - if (modelElement instanceof IGeneralization) { - IGeneralization generalization = (IGeneralization) modelElement; - ElementNode newParent; + IAttribute[] attributes = _class.toAttributeArray(); - if (generalization.getFrom() != null && generalization.getTo() != null) { - newParent = new ElementNode(generalization); - newRoot.add(newParent); - } - } + for (int j = 0; attributes != null && j < attributes.length; j++) + newParent.add(new ElementNode(attributes[j])); - if (modelElement instanceof IAssociationClass) { - IAssociationClass associationClass = (IAssociationClass) modelElement; - ElementNode newParent; + newRoot.add(newParent); + } - newParent = new ElementNode(associationClass); - newRoot.add(newParent); - } + if (modelElement instanceof IAssociation) { + IAssociation association = (IAssociation) modelElement; + ElementNode newParent; - return newRoot; - } + newParent = new ElementNode(association); - private static ElementNode setChildrenFromDiagrams(IDiagramUIModel diagram, ElementNode parent) { - ElementNode newRoot = parent; + IAssociationEnd fromEnd = (IAssociationEnd) association.getFromEnd(); + IAssociationEnd toEnd = (IAssociationEnd) association.getToEnd(); - IDiagramElement[] models = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_MODEL); - IDiagramElement[] pckgs = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_PACKAGE); - IDiagramElement[] classes = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_CLASS); - IDiagramElement[] associations = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_ASSOCIATION); - IDiagramElement[] generalizationSets = diagram - .toDiagramElementArray(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET); - IDiagramElement[] generalizations = diagram - .toDiagramElementArray(IModelElementFactory.MODEL_TYPE_GENERALIZATION); - IDiagramElement[] associationClasses = diagram - .toDiagramElementArray(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS); + if (fromEnd != null) + newParent.add(new ElementNode(fromEnd)); - for (int i = 0; models != null && i < models.length; i++) { - if (models[i].getModelElement() != null) { - IModel model = (IModel) models[i].getModelElement(); + if (toEnd != null) + newParent.add(new ElementNode(toEnd)); - ElementNode newParent; - newParent = new ElementNode(model); + newRoot.add(newParent); + } - newRoot.add(newParent); + if (modelElement instanceof IDataType) { + IDataType _class = (IDataType) modelElement; - IModelElement[] elements = model.toChildArray(); + ElementNode newParent; + newParent = new ElementNode(_class); - for (int j = 0; elements != null && j < elements.length; j++) - setChildrenRecursively(elements[i], newParent); - } - } + newRoot.add(newParent); + } - for (int i = 0; pckgs != null && i < pckgs.length; i++) { - if (pckgs[i].getModelElement() != null) { - IPackage pckg = (IPackage) pckgs[i].getModelElement(); + if (modelElement instanceof IGeneralizationSet) { + IGeneralizationSet generalizationSet = (IGeneralizationSet) modelElement; + ElementNode newParent; - ElementNode newParent; - newParent = new ElementNode(pckg); + newParent = new ElementNode(generalizationSet); + newRoot.add(newParent); + } - newRoot.add(newParent); + if (modelElement instanceof IGeneralization) { + IGeneralization generalization = (IGeneralization) modelElement; + ElementNode newParent; - IModelElement[] elements = pckg.toChildArray(); + if (generalization.getFrom() != null && generalization.getTo() != null) { + newParent = new ElementNode(generalization); + newRoot.add(newParent); + } + } - for (int j = 0; elements != null && j < elements.length; j++) - setChildrenRecursively(elements[i], newParent); - } - } + if (modelElement instanceof IAssociationClass) { + IAssociationClass associationClass = (IAssociationClass) modelElement; + ElementNode newParent; - for (int i = 0; classes != null && i < classes.length; i++) { - if (classes[i].getModelElement() != null) { - IClass _class = (IClass) classes[i].getModelElement(); + newParent = new ElementNode(associationClass); + newRoot.add(newParent); + } + + return newRoot; + } - ElementNode newParent; - newParent = new ElementNode(_class); + private static ElementNode setChildrenFromDiagrams(IDiagramUIModel diagram, ElementNode parent) { + ElementNode newRoot = parent; - IAttribute[] attributes = _class.toAttributeArray(); + IDiagramElement[] models = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_MODEL); + IDiagramElement[] pckgs = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_PACKAGE); + IDiagramElement[] classes = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_CLASS); + IDiagramElement[] associations = diagram.toDiagramElementArray(IModelElementFactory.MODEL_TYPE_ASSOCIATION); + IDiagramElement[] generalizationSets = diagram + .toDiagramElementArray(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET); + IDiagramElement[] generalizations = diagram + .toDiagramElementArray(IModelElementFactory.MODEL_TYPE_GENERALIZATION); + IDiagramElement[] associationClasses = diagram + .toDiagramElementArray(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS); - for (int j = 0; attributes != null && j < attributes.length; j++) - newParent.add(new ElementNode(attributes[j])); + for (int i = 0; models != null && i < models.length; i++) { + if (models[i].getModelElement() != null) { + IModel model = (IModel) models[i].getModelElement(); - newRoot.add(newParent); - } - } + ElementNode newParent; + newParent = new ElementNode(model); - for (int i = 0; associations != null && i < associations.length; i++) { - if (associations[i].getModelElement() != null) { - IAssociation association = (IAssociation) associations[i].getModelElement(); - ElementNode newParent; + newRoot.add(newParent); - newParent = new ElementNode(association); + IModelElement[] elements = model.toChildArray(); - IAssociationEnd fromEnd = (IAssociationEnd) association.getFromEnd(); - IAssociationEnd toEnd = (IAssociationEnd) association.getToEnd(); - - if (fromEnd != null) - newParent.add(new ElementNode(fromEnd)); + for (int j = 0; elements != null && j < elements.length; j++) + setChildrenRecursively(elements[i], newParent); + } + } - if (toEnd != null) - newParent.add(new ElementNode(toEnd)); + for (int i = 0; pckgs != null && i < pckgs.length; i++) { + if (pckgs[i].getModelElement() != null) { + IPackage pckg = (IPackage) pckgs[i].getModelElement(); - newRoot.add(newParent); + ElementNode newParent; + newParent = new ElementNode(pckg); - } - } + newRoot.add(newParent); - for (int i = 0; generalizationSets != null && i < generalizationSets.length; i++) { - if (generalizationSets[i].getModelElement() != null) { - IGeneralizationSet generalizationSet = (IGeneralizationSet) generalizationSets[i].getModelElement(); - ElementNode newParent; + IModelElement[] elements = pckg.toChildArray(); - newParent = new ElementNode(generalizationSet); - newRoot.add(newParent); - } - } + for (int j = 0; elements != null && j < elements.length; j++) + setChildrenRecursively(elements[i], newParent); + } + } - for (int i = 0; generalizations != null && i < generalizations.length; i++) { - if (generalizations[i].getModelElement() != null) { - IGeneralization generalization = (IGeneralization) generalizations[i].getModelElement(); - ElementNode newParent; + for (int i = 0; classes != null && i < classes.length; i++) { + if (classes[i].getModelElement() != null) { + IClass _class = (IClass) classes[i].getModelElement(); - newParent = new ElementNode(generalization); - newRoot.add(newParent); - } - } + ElementNode newParent; + newParent = new ElementNode(_class); - for (int i = 0; associationClasses != null && i < associationClasses.length; i++) { - if (associationClasses[i].getModelElement() != null) { - IAssociationClass associationClass = (IAssociationClass) associationClasses[i].getModelElement(); - ElementNode newParent; + IAttribute[] attributes = _class.toAttributeArray(); - newParent = new ElementNode(associationClass); - newRoot.add(newParent); - } - } + for (int j = 0; attributes != null && j < attributes.length; j++) + newParent.add(new ElementNode(attributes[j])); - return newRoot; - } + newRoot.add(newParent); + } + } - private void visitAllNodesAndCheckSameId(ElementNode root, String id) { + for (int i = 0; associations != null && i < associations.length; i++) { + if (associations[i].getModelElement() != null) { + IAssociation association = (IAssociation) associations[i].getModelElement(); + ElementNode newParent; - TreeNode[] treeNode = root.getPath(); - TreePath tp = new TreePath(treeNode); - CheckedNode cn = new CheckedNode(false, root.getChildCount() > 0, false); - - TreePath parentPath = tp.getParentPath(); - // the root item is assumed to be always selected if not this function is not - // called - if (parentPath == null) { - cn.isSelected = true; - checkedPaths.add(tp); - nodesCheckingState.put(tp, cn); - } - - // if modelElement - if (((ElementNode) root).getUserObject() instanceof IModelElement) { - IModelElement nodeElement = (IModelElement) root.getUserObject(); - - if (nodeElement.getId().contentEquals(id)) { - cn.isSelected = true; - checkedPaths.add(tp); - nodesCheckingState.put(tp, cn); - } - } - - // if Diagram - if (((ElementNode) root).getUserObject() instanceof IDiagramUIModel) { - IDiagramUIModel diagramElement = (IDiagramUIModel) root.getUserObject(); - - if (diagramElement.getId().contentEquals(id)) { - cn.isSelected = true; - checkedPaths.add(tp); - nodesCheckingState.put(tp, cn); - } - } - - if (root.getChildCount() >= 0) { - for (Enumeration e = root.children(); e.hasMoreElements(); ) { - ElementNode n = (ElementNode) e.nextElement(); - - visitAllNodesAndCheckSameId(n, id); - } - } - } - - public void setNodesCheck(HashSet idElements) { - resetCheckingState(); - ElementNode root = (ElementNode) treeModel.getRoot(); - - Iterator ite = idElements.iterator(); - - while (ite.hasNext()) { - String id = ite.next(); - visitAllNodesAndCheckSameId(root, id); - } - - } - -public static class ElementNode extends DefaultMutableTreeNode { - - private static final long serialVersionUID = 1L; - - public ElementNode(Object userObject) { - super(userObject); - } - - @Override - public void add(MutableTreeNode newChild) { - super.add(newChild); - sort(); - } - - @SuppressWarnings("unchecked") - public void sort() { - Collections.sort(children, compare()); - } - - @SuppressWarnings("rawtypes") - private Comparator compare() { - return new Comparator() { - @Override - public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) { - String arg1 = ""; - String arg2 = ""; - - if (o1 == null) - return 0; - if (o2 == null) - return 0; - - if (o1.getUserObject() instanceof IDiagramUIModel) { - if (o2.getUserObject() instanceof IDiagramUIModel) { - return ((IDiagramUIModel) o1.getUserObject()).getName() - .compareTo(((IDiagramUIModel) o2.getUserObject()).getName()); - } else { - return 0; - } - } - - if (o1.getUserObject() instanceof IModelElement) { - if (o2.getUserObject() instanceof IModelElement) { - IModelElement element1 = (IModelElement) o1.getUserObject(); - IModelElement element2 = (IModelElement) o2.getUserObject(); - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE) - && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE) - && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL) - && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { - return -1; - } else if (element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { - return 1; - } - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL) - && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { - return -1; - } else if (element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { - return 1; - } - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS) - && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS)) { - return -1; - } else if (element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS)) { - return 1; - } - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION) - && element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { - return -1; - } else if (element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { - return 1; - } - - if (element1.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET) - && element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET)) { - return -1; - } else if (element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET)) { - return 1; - } - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION) - && element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION)) { - return -1; - } else if (element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION)) { - return 1; - } - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS) - && element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS)) { - return -1; - } else if (element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS)) { - return 1; - } - - if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE) - && element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE)) { - arg1 = element1.getName(); - arg2 = element2.getName(); - } else if (element1.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE)) { - return -1; - } else if (element2.getModelType() - .contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE)) { - return 1; - } - - } - } - - if (arg1 == null) - arg1 = ""; - if (arg2 == null) - arg2 = ""; - - return arg1.compareTo(arg2); - } - - }; - - } -} + newParent = new ElementNode(association); + + IAssociationEnd fromEnd = (IAssociationEnd) association.getFromEnd(); + IAssociationEnd toEnd = (IAssociationEnd) association.getToEnd(); + + if (fromEnd != null) + newParent.add(new ElementNode(fromEnd)); + + if (toEnd != null) + newParent.add(new ElementNode(toEnd)); + + newRoot.add(newParent); + + } + } + + for (int i = 0; generalizationSets != null && i < generalizationSets.length; i++) { + if (generalizationSets[i].getModelElement() != null) { + IGeneralizationSet generalizationSet = (IGeneralizationSet) generalizationSets[i].getModelElement(); + ElementNode newParent; + + newParent = new ElementNode(generalizationSet); + newRoot.add(newParent); + } + } + + for (int i = 0; generalizations != null && i < generalizations.length; i++) { + if (generalizations[i].getModelElement() != null) { + IGeneralization generalization = (IGeneralization) generalizations[i].getModelElement(); + ElementNode newParent; + + newParent = new ElementNode(generalization); + newRoot.add(newParent); + } + } + + for (int i = 0; associationClasses != null && i < associationClasses.length; i++) { + if (associationClasses[i].getModelElement() != null) { + IAssociationClass associationClass = (IAssociationClass) associationClasses[i].getModelElement(); + ElementNode newParent; + + newParent = new ElementNode(associationClass); + newRoot.add(newParent); + } + } + + return newRoot; + } + + @SuppressWarnings("unchecked") + private void visitAllNodesAndCheckSameId(ElementNode root, String id) { + TreeNode[] treeNode = root.getPath(); + TreePath tp = new TreePath(treeNode); + CheckedNode cn = new CheckedNode(false, root.getChildCount() > 0, false); + + TreePath parentPath = tp.getParentPath(); + // the root item is assumed to be always selected if not this function is not + // called + if (parentPath == null) { + cn.isSelected = true; + checkedPaths.add(tp); + nodesCheckingState.put(tp, cn); + } + + // if modelElement + if (((ElementNode) root).getUserObject() instanceof IModelElement) { + IModelElement nodeElement = (IModelElement) root.getUserObject(); + + if (nodeElement.getId().contentEquals(id)) { + cn.isSelected = true; + checkedPaths.add(tp); + nodesCheckingState.put(tp, cn); + } + } + + // if Diagram + if (((ElementNode) root).getUserObject() instanceof IDiagramUIModel) { + IDiagramUIModel diagramElement = (IDiagramUIModel) root.getUserObject(); + + if (diagramElement.getId().contentEquals(id)) { + cn.isSelected = true; + checkedPaths.add(tp); + nodesCheckingState.put(tp, cn); + } + } + + if (root.getChildCount() >= 0) { + for (Enumeration e = root.children(); e.hasMoreElements();) { + ElementNode n = (ElementNode) e.nextElement(); + + visitAllNodesAndCheckSameId(n, id); + } + } + } + + public void setNodesCheck(HashSet idElements) { + resetCheckingState(); + ElementNode root = (ElementNode) treeModel.getRoot(); + + Iterator ite = idElements.iterator(); + + while (ite.hasNext()) { + String id = ite.next(); + visitAllNodesAndCheckSameId(root, id); + } + + } + + public static class ElementNode extends DefaultMutableTreeNode { + + private static final long serialVersionUID = 1L; + + public ElementNode(Object userObject) { + super(userObject); + } + + @Override + public void add(MutableTreeNode newChild) { + super.add(newChild); + sort(); + } + + @SuppressWarnings("unchecked") + public void sort() { + Collections.sort(children, compare()); + } + + @SuppressWarnings("rawtypes") + private Comparator compare() { + return new Comparator() { + @Override + public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) { + String arg1 = ""; + String arg2 = ""; + + if (o1 == null) + return 0; + if (o2 == null) + return 0; + + if (o1.getUserObject() instanceof IDiagramUIModel) { + if (o2.getUserObject() instanceof IDiagramUIModel) { + return ((IDiagramUIModel) o1.getUserObject()).getName() + .compareTo(((IDiagramUIModel) o2.getUserObject()).getName()); + } else { + return 0; + } + } + + if (o1.getUserObject() instanceof IModelElement) { + if (o2.getUserObject() instanceof IModelElement) { + IModelElement element1 = (IModelElement) o1.getUserObject(); + IModelElement element2 = (IModelElement) o2.getUserObject(); + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE) + && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE) + && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL) + && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { + return -1; + } else if (element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_PACKAGE)) { + return 1; + } + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL) + && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { + return -1; + } else if (element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_MODEL)) { + return 1; + } + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS) + && element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS)) { + return -1; + } else if (element2.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_CLASS)) { + return 1; + } + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION) + && element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { + return -1; + } else if (element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION)) { + return 1; + } + + if (element1.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET) + && element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET)) { + return -1; + } else if (element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION_SET)) { + return 1; + } + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION) + && element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION)) { + return -1; + } else if (element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_GENERALIZATION)) { + return 1; + } + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS) + && element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS)) { + return -1; + } else if (element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_ASSOCIATION_CLASS)) { + return 1; + } + + if (element1.getModelType().contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE) + && element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE)) { + arg1 = element1.getName(); + arg2 = element2.getName(); + } else if (element1.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE)) { + return -1; + } else if (element2.getModelType() + .contentEquals(IModelElementFactory.MODEL_TYPE_DATA_TYPE)) { + return 1; + } + + } + } + + if (arg1 == null) + arg1 = ""; + if (arg2 == null) + arg2 = ""; + + return arg1.compareTo(arg2); + } + + }; + + } + } } \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/NameUtil.java b/src/main/java/it/unibz/inf/ontouml/vp/views/NameUtil.java deleted file mode 100644 index 8ed9134e..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/NameUtil.java +++ /dev/null @@ -1,81 +0,0 @@ -package it.unibz.inf.ontouml.vp.views; - -import com.vp.plugin.diagram.IDiagramUIModel; -import com.vp.plugin.model.*; - -public class NameUtil { - - public static String getDisplayName(Object obj) { - if (obj == null) - return ""; - - if(obj instanceof String) - return obj.toString(); - - if(obj instanceof IDiagramUIModel) { - IDiagramUIModel diagram = (IDiagramUIModel) obj; - - return diagram.getName() != null ? diagram.getName(): "Diagram"; - } - - if (obj instanceof IAttribute) { - IAttribute attribute = (IAttribute) obj; - - String attributeName = attribute.getName() != null ? attribute.getName() : ""; - - String attributeType = ""; - if (attribute.getType() != null) - attributeType = attribute.getTypeAsString(); - - return attributeName + " : " + attributeType; - } - - if (obj instanceof IAssociation) { - IAssociation association = (IAssociation) obj; - String assocName = ""; - - if (association.getName() != null && !association.getName().equals("")) - assocName = association.getName() + " "; - - String nameFrom = association.getFrom() == null ? "" : association.getFrom().getName(); - String nameTo = association.getTo() == null ? "" : association.getTo().getName(); - - return assocName + "(" + nameFrom + " -> " + nameTo + ")"; - } - - if (obj instanceof IAssociationEnd) { - IAssociationEnd assocEnd = (IAssociationEnd) obj; - - String endName = assocEnd.getName() != null ? assocEnd.getName() : ""; - String typeName = assocEnd.getType() != null ? assocEnd.getTypeAsString() : ""; - - return endName + " : " + typeName; - } - - if (obj instanceof IGeneralization) { - IGeneralization generalization = (IGeneralization) obj; - - String childTypeName = generalization.getTo() != null ? generalization.getTo().getName() : ""; - String parentTypeName = generalization.getFrom() != null ? generalization.getFrom().getName() : ""; - - return "(" + childTypeName + " -> " + parentTypeName + ")"; - } - - if (obj instanceof IAssociationClass) { - IAssociationClass assocClass = (IAssociationClass) obj; - - String nameFrom = assocClass.getFrom() != null ? assocClass.getFrom().getName() : ""; - String nameTo = assocClass.getTo() != null ? assocClass.getTo().getName() : ""; - - return "(" + nameFrom + " -> " + nameTo + ")"; - - } - - if( obj instanceof IModelElement) { - IModelElement element = (IModelElement) obj; - return element.getName() != null ? element.getName() : "ModelElement " + element.getId(); - } - - return "Element"; - } -} diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/ProgressPanel.java b/src/main/java/it/unibz/inf/ontouml/vp/views/ProgressPanel.java index f2349a4c..59ead0ce 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/ProgressPanel.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/ProgressPanel.java @@ -1,7 +1,7 @@ package it.unibz.inf.ontouml.vp.views; -import it.unibz.inf.ontouml.vp.utils.ServerRequest; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.model.ServerRequest; +import it.unibz.inf.ontouml.vp.utils.ViewManagerUtils; import java.awt.Dimension; import java.awt.GridBagConstraints; @@ -49,7 +49,7 @@ public ProgressPanel(ServerRequest request) { public void actionPerformed(ActionEvent e) { request.doStop(); _dialog.close(); - ViewUtils.cleanAndShowMessage("Request cancelled by the user."); + ViewManagerUtils.cleanAndShowMessage("Request cancelled by the user."); } }); diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/SelectMultipleOptionsDialog.java b/src/main/java/it/unibz/inf/ontouml/vp/views/SelectMultipleOptionsDialog.java deleted file mode 100644 index 46536a74..00000000 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/SelectMultipleOptionsDialog.java +++ /dev/null @@ -1,202 +0,0 @@ -package it.unibz.inf.ontouml.vp.views; - -import java.awt.Component; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; - -import com.vp.plugin.view.IDialog; -import com.vp.plugin.view.IDialogHandler; - -import it.unibz.inf.ontouml.vp.utils.Configurations; -import it.unibz.inf.ontouml.vp.utils.StereotypeUtils; - -public class SelectMultipleOptionsDialog implements IDialogHandler { - - private IDialog _dialog; - // private Component _component; - private JPanel _selectionsPane; - private boolean cancelledExit = true; - private String initialSelecteion; - - public SelectMultipleOptionsDialog(String selectedValues) { - super(); - - this.initialSelecteion = selectedValues; - this._selectionsPane = new JPanel(); - this.setSelectedValues(selectedValues); - this._selectionsPane.setBorder(new EmptyBorder(7, 0, 0, 0)); - } - - @Override - public Component getComponent() { - final JLabel line = new JLabel("Select the possible ontological natures of the type's instances."); - final JButton cancelButton = new JButton("Cancel"); - final JButton applyButton = new JButton("Apply"); - - applyButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - cancelledExit = false; - _dialog.close(); - } - }); - - cancelButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - cancelledExit = true; - _dialog.close(); - } - }); - - // JPanel panel = new JPanel(); - JPanel panel = new JPanel(); - - panel.setLayout(new BoxLayout(panel,BoxLayout.PAGE_AXIS)); - - panel.add(line); - panel.add(this._selectionsPane); - - JPanel buttonsPanel = new JPanel(); - buttonsPanel.setLayout(new FlowLayout()); - buttonsPanel.add(applyButton); - buttonsPanel.add(cancelButton); - panel.add(buttonsPanel); - - line.setAlignmentX(Component.LEFT_ALIGNMENT); - this._selectionsPane.setAlignmentX(Component.LEFT_ALIGNMENT); - buttonsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - - // this._component = panel; - - return panel; - } - - @Override - public void prepare(IDialog dialog) { - this._dialog = dialog; - dialog.setTitle("Restrict allowed natures"); - dialog.pack(); - } - - @Override - public boolean canClosed() { - return true; - } - - @Override - public void shown() {} - - public String getSelectedValues() { - if(this.cancelledExit) { - return this.initialSelecteion; - } - - final StringBuilder selectedValues = new StringBuilder(""); - final Component[] checkBoxes = this._selectionsPane.getComponents(); - - for (int i = 0; checkBoxes != null && i < checkBoxes.length; i++) { - if(checkBoxes[i] instanceof JCheckBox) { - final JCheckBox checkBox = (JCheckBox) checkBoxes[i]; - if(checkBox.isSelected()) { - selectedValues.append(selectedValues.length() == 0 ? - checkBox.getText() : " " + checkBox.getText()); - } - } - } - - return selectedValues.toString(); - } - - public void setSelectedValues(String selectedValuesString) { - final List selectedList = - Arrays.asList(selectedValuesString.split("\\s+")); - final List restrictedNatures = StereotypeUtils.getRestrictionsList(); - Collections.sort(restrictedNatures); - final boolean isSmartModelingEnabled = Configurations.getInstance() - .getProjectConfigurations().isSmartModellingEnabled(); - - this._selectionsPane.setLayout(new GridLayout(4,3)); - - JCheckBox checkBox; - - // Line 1, Column 1 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_COLLECTIVE); - this._selectionsPane.add(checkBox); - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_COLLECTIVE)); - // Line 1, Column 2 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_MODE); - this._selectionsPane.add(checkBox); - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_MODE)); - // Line 1, Column 3 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_ABSTRACT); - this._selectionsPane.add(checkBox); - if(isSmartModelingEnabled) { - checkBox.setSelected(false); - checkBox.setEnabled(false); - } else { - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_ABSTRACT)); - } - - // Line 2, Column 1 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_FUNCTIONAL_COMPLEX); - this._selectionsPane.add(checkBox); - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_FUNCTIONAL_COMPLEX)); - // Line 2, Column 2 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_QUALITY); - this._selectionsPane.add(checkBox); - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_QUALITY)); - // Line 2, Column 3 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_EVENT); - this._selectionsPane.add(checkBox); - if(isSmartModelingEnabled) { - checkBox.setSelected(false); - checkBox.setEnabled(false); - } else { - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_EVENT)); - } - - // Line 3, Column 1 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_QUANTITY); - this._selectionsPane.add(checkBox); - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_QUANTITY)); - // Line 3, Column 2 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_RELATOR); - this._selectionsPane.add(checkBox); - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_RELATOR)); - // Line 3, Column 3 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_SITUATION); - this._selectionsPane.add(checkBox); - if(isSmartModelingEnabled) { - checkBox.setSelected(false); - checkBox.setEnabled(false); - } else { - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_SITUATION)); - } - - // Line 4, Column 1 - this._selectionsPane.add(new JLabel()); - // Line 4, Column 2 - this._selectionsPane.add(new JLabel()); - // Line 4, Column 3 - checkBox = new JCheckBox(StereotypeUtils.RESTRICTED_TO_TYPE); - this._selectionsPane.add(checkBox); - if(isSmartModelingEnabled) { - checkBox.setSelected(false); - checkBox.setEnabled(false); - } else { - checkBox.setSelected(selectedList.contains(StereotypeUtils.RESTRICTED_TO_TYPE)); - } - } - -} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/SelectRestrictionsView.java b/src/main/java/it/unibz/inf/ontouml/vp/views/SelectRestrictionsView.java new file mode 100644 index 00000000..7c4d35b1 --- /dev/null +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/SelectRestrictionsView.java @@ -0,0 +1,197 @@ +package it.unibz.inf.ontouml.vp.views; + +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; + +import com.vp.plugin.view.IDialog; +import com.vp.plugin.view.IDialogHandler; + +import it.unibz.inf.ontouml.vp.model.Configurations; +import it.unibz.inf.ontouml.vp.utils.StereotypesManager; + +public class SelectRestrictionsView implements IDialogHandler { + + private IDialog _dialog; + private JPanel _selectionsPane; + private boolean cancelledExit = true; + private String initialSelecteion; + + public SelectRestrictionsView(String selectedValues) { + super(); + + this.initialSelecteion = selectedValues; + this._selectionsPane = new JPanel(); + this.setSelectedValues(selectedValues); + this._selectionsPane.setBorder(new EmptyBorder(7, 0, 0, 0)); + } + + @Override + public Component getComponent() { + final JLabel line = new JLabel("Select the possible ontological natures of the type's instances."); + final JButton cancelButton = new JButton("Cancel"); + final JButton applyButton = new JButton("Apply"); + + applyButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + cancelledExit = false; + _dialog.close(); + } + }); + + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + cancelledExit = true; + _dialog.close(); + } + }); + + JPanel panel = new JPanel(); + + panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); + + panel.add(line); + panel.add(this._selectionsPane); + + JPanel buttonsPanel = new JPanel(); + buttonsPanel.setLayout(new FlowLayout()); + buttonsPanel.add(applyButton); + buttonsPanel.add(cancelButton); + panel.add(buttonsPanel); + + line.setAlignmentX(Component.LEFT_ALIGNMENT); + this._selectionsPane.setAlignmentX(Component.LEFT_ALIGNMENT); + buttonsPanel.setAlignmentX(Component.LEFT_ALIGNMENT); + + return panel; + } + + @Override + public void prepare(IDialog dialog) { + this._dialog = dialog; + dialog.setTitle("Restrict allowed natures"); + dialog.pack(); + } + + @Override + public boolean canClosed() { + return true; + } + + @Override + public void shown() { + } + + public String getSelectedValues() { + if (this.cancelledExit) { + return this.initialSelecteion; + } + + final StringBuilder selectedValues = new StringBuilder(""); + final Component[] checkBoxes = this._selectionsPane.getComponents(); + + for (int i = 0; checkBoxes != null && i < checkBoxes.length; i++) { + if (checkBoxes[i] instanceof JCheckBox) { + final JCheckBox checkBox = (JCheckBox) checkBoxes[i]; + if (checkBox.isSelected()) { + selectedValues.append(selectedValues.length() == 0 ? checkBox.getText() : " " + checkBox.getText()); + } + } + } + + return selectedValues.toString(); + } + + public void setSelectedValues(String selectedValuesString) { + final List selectedList = Arrays.asList(selectedValuesString.split("\\s+")); + final List restrictedNatures = StereotypesManager.getRestrictionsList(); + Collections.sort(restrictedNatures); + final boolean isSmartModelingEnabled = Configurations.getInstance().getProjectConfigurations() + .isSmartModellingEnabled(); + + this._selectionsPane.setLayout(new GridLayout(4, 3)); + + JCheckBox checkBox; + + // Line 1, Column 1 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_COLLECTIVE); + this._selectionsPane.add(checkBox); + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_COLLECTIVE)); + // Line 1, Column 2 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_MODE); + this._selectionsPane.add(checkBox); + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_MODE)); + // Line 1, Column 3 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_ABSTRACT); + this._selectionsPane.add(checkBox); + if (isSmartModelingEnabled) { + checkBox.setSelected(false); + checkBox.setEnabled(false); + } else { + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_ABSTRACT)); + } + + // Line 2, Column 1 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_FUNCTIONAL_COMPLEX); + this._selectionsPane.add(checkBox); + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_FUNCTIONAL_COMPLEX)); + // Line 2, Column 2 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_QUALITY); + this._selectionsPane.add(checkBox); + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_QUALITY)); + // Line 2, Column 3 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_EVENT); + this._selectionsPane.add(checkBox); + if (isSmartModelingEnabled) { + checkBox.setSelected(false); + checkBox.setEnabled(false); + } else { + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_EVENT)); + } + + // Line 3, Column 1 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_QUANTITY); + this._selectionsPane.add(checkBox); + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_QUANTITY)); + // Line 3, Column 2 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_RELATOR); + this._selectionsPane.add(checkBox); + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_RELATOR)); + // Line 3, Column 3 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_SITUATION); + this._selectionsPane.add(checkBox); + if (isSmartModelingEnabled) { + checkBox.setSelected(false); + checkBox.setEnabled(false); + } else { + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_SITUATION)); + } + + // Line 4, Column 1 (empty) + this._selectionsPane.add(new JLabel()); + // Line 4, Column 2 (empty) + this._selectionsPane.add(new JLabel()); + // Line 4, Column 3 + checkBox = new JCheckBox(StereotypesManager.RESTRICTED_TO_TYPE); + this._selectionsPane.add(checkBox); + if (isSmartModelingEnabled) { + checkBox.setSelected(false); + checkBox.setEnabled(false); + } else { + checkBox.setSelected(selectedList.contains(StereotypesManager.RESTRICTED_TO_TYPE)); + } + } + +} \ No newline at end of file diff --git a/src/main/java/it/unibz/inf/ontouml/vp/views/SetOrderDialog.java b/src/main/java/it/unibz/inf/ontouml/vp/views/SetOrderView.java similarity index 76% rename from src/main/java/it/unibz/inf/ontouml/vp/views/SetOrderDialog.java rename to src/main/java/it/unibz/inf/ontouml/vp/views/SetOrderView.java index ea5db111..ba161659 100644 --- a/src/main/java/it/unibz/inf/ontouml/vp/views/SetOrderDialog.java +++ b/src/main/java/it/unibz/inf/ontouml/vp/views/SetOrderView.java @@ -5,6 +5,8 @@ import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; +import java.nio.file.Paths; import javax.swing.BoxLayout; import javax.swing.ImageIcon; @@ -14,20 +16,28 @@ import javax.swing.JTextField; import javax.swing.border.EmptyBorder; +import com.vp.plugin.ApplicationManager; import com.vp.plugin.view.IDialog; import com.vp.plugin.view.IDialogHandler; -import it.unibz.inf.ontouml.vp.utils.ViewUtils; +import it.unibz.inf.ontouml.vp.OntoUMLPlugin; -public class SetOrderDialog implements IDialogHandler { +public class SetOrderView implements IDialogHandler { + + + private static final String ADD_LOGO = "add"; + private static final String ASTERISK_LOGO = "asterisk"; + private static final String SUBTRACT_LOGO = "subtract"; + private static final String ADD_LOGO_FILENAME = "add.png"; + private static final String ASTERISK_LOGO_FILENAME = "asterisk.png"; + private static final String SUBTRACT_LOGO_FILENAME = "subtract.png"; private IDialog _dialog; - // private Component _component; private boolean cancelledExit = true; private String currentString = ""; private JTextField _inputField; - public SetOrderDialog(String current) { + public SetOrderView(String current) { super(); this.currentString = current; } @@ -40,11 +50,11 @@ public Component getComponent() { _inputField = new JTextField(this.currentString); _inputField.setColumns(10); - ImageIcon addIcon = new ImageIcon(ViewUtils.getFilePath(ViewUtils.ADD_LOGO)); + ImageIcon addIcon = new ImageIcon(getFilePath(ADD_LOGO)); addIcon.setImage(addIcon.getImage().getScaledInstance(17, 17, Image.SCALE_SMOOTH)); - ImageIcon subtractIcon = new ImageIcon(ViewUtils.getFilePath(ViewUtils.SUBTRACT_LOGO)); + ImageIcon subtractIcon = new ImageIcon(getFilePath(SUBTRACT_LOGO)); subtractIcon.setImage(subtractIcon.getImage().getScaledInstance(17, 17, Image.SCALE_SMOOTH)); - ImageIcon asteriskIcon = new ImageIcon(ViewUtils.getFilePath(ViewUtils.ASTERISK_LOGO)); + ImageIcon asteriskIcon = new ImageIcon(getFilePath(ASTERISK_LOGO)); asteriskIcon.setImage(asteriskIcon.getImage().getScaledInstance(17, 17, Image.SCALE_SMOOTH)); final JButton addButton = new JButton(addIcon); @@ -124,8 +134,6 @@ public void actionPerformed(ActionEvent e) { line.setAlignmentX(Component.LEFT_ALIGNMENT); bottomPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - - // this._component = panel; return panel; } @@ -148,5 +156,20 @@ public void shown() {} public String getOrder() { return this.cancelledExit ? this.currentString : this._inputField.getText(); } + + private static String getFilePath(String imageName) { + final File pluginDir = ApplicationManager.instance().getPluginInfo(OntoUMLPlugin.PLUGIN_ID).getPluginDir(); + + switch (imageName) { + case ADD_LOGO: + return Paths.get(pluginDir.getAbsolutePath(), "icons", ADD_LOGO_FILENAME).toFile().getAbsolutePath(); + case ASTERISK_LOGO: + return Paths.get(pluginDir.getAbsolutePath(), "icons", ASTERISK_LOGO_FILENAME).toFile().getAbsolutePath(); + case SUBTRACT_LOGO: + return Paths.get(pluginDir.getAbsolutePath(), "icons", SUBTRACT_LOGO_FILENAME).toFile().getAbsolutePath(); + default: + return null; + } + } } \ No newline at end of file diff --git a/src/main/resources/plugin.xml b/src/main/resources/plugin.xml index 6b14efd9..cf3f0f74 100644 --- a/src/main/resources/plugin.xml +++ b/src/main/resources/plugin.xml @@ -10,6 +10,7 @@ id="it.unibz.inf.ontouml.vp.actionset1.toolbar1" orientation="north" index="last"/> + - + + - + + + + - + label="Export to JSON" + menuPath="it.unibz.inf.ontouml.vp.actionset1.toolbar1/it.unibz.inf.ontouml.vp.actionset1.menu1/#"> + - + menuPath="it.unibz.inf.ontouml.vp.actionset1.toolbar1/it.unibz.inf.ontouml.vp.actionset1.menu1/#"> + - + tooltip="Opens the plugin update dialog." + icon="icons/toolbar/update-orange.png" + label="Update Plugin" + menuPath="it.unibz.inf.ontouml.vp.actionset1.toolbar1/it.unibz.inf.ontouml.vp.actionset1.menu1/#"> + + + - + menuPath="it.unibz.inf.ontouml.vp.actionset1.toolbar1/it.unibz.inf.ontouml.vp.actionset1.menu1/#"> + - - - - + menuPath="it.unibz.inf.ontouml.vp.actionset1.toolbar1/it.unibz.inf.ontouml.vp.actionset1.menu1/#"> + + @@ -115,30 +113,30 @@ - ` + - + - + - + - + - + - + @@ -149,93 +147,93 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -247,81 +245,81 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -334,93 +332,93 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -432,81 +430,81 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -518,11 +516,11 @@ - + - +