diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/exceptions/FeatureHasNoPaletteDescriptorException.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/exceptions/FeatureHasNoPaletteDescriptorException.java new file mode 100644 index 0000000000000000000000000000000000000000..9f4a44e4ef03045511f3f671328f6ee028951043 --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/exceptions/FeatureHasNoPaletteDescriptorException.java @@ -0,0 +1,31 @@ +package org.framed.iorm.ui.exceptions; + +import org.framed.iorm.ui.literals.TextLiterals; +import org.framed.iorm.ui.palette.FeaturePaletteDescriptor; +import org.framed.iorm.ui.providers.ToolBehaviorProvider; + +/** + * This exception is thrown when a feature has no {@link FeaturePaletteDescriptor} when the + * {@link ToolBehaviorProvider} builds the palette. + * @author Kevin Kassin + */ +public class FeatureHasNoPaletteDescriptorException extends RuntimeException { + + /** + * serial + */ + private static final long serialVersionUID = -1153983811660560751L; + + /** + * the exceptions message gathered from {@link TextLiterals} + */ + private static final String FEATURE_HAS_NO_DESCRIPTOR_MESSAGE = TextLiterals.FEATURE_HAS_NO_DESCRIPTOR_MESSAGE; + + /** + * Class constructor + */ + public FeatureHasNoPaletteDescriptorException(String featureName) { + super(FEATURE_HAS_NO_DESCRIPTOR_MESSAGE + featureName); + } + +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/IdentifierLiterals.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/IdentifierLiterals.java index 09cd20b604b3c77934b47b5f0861b00670db1511..064cb6f903e80649ef1ee79927827dd36f48c851 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/IdentifierLiterals.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/IdentifierLiterals.java @@ -261,14 +261,4 @@ public class IdentifierLiterals { DIAGRAM_KIND_MAIN_DIAGRAM = "main_diagram", DIAGRAM_KIND_GROUP_DIAGRAM = "group_diagram", DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM = "compartment_diagram"; - - /** - * identifiers to differ between the editor palettes - * <p> - * can be:<br> - * (1) the palette type used outside a stepped in compartment type or<br> - * (2) the pallete type used in a editor of a diagram of a compartment type - */ - public static final String PALETTE_TYPE_TOPLEVELVIEW = "palette_type_toplevel", - PALETTE_TYPE_COMPARTMENTVIEW = "palette_type_compartment"; } diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/NameLiterals.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/NameLiterals.java index 9ee84ebe90453fb3e2d9e05f0d6a10b5b2799837..eee0ff0b34312ea3ba6d7dc87fdaa69a649ef38c 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/NameLiterals.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/NameLiterals.java @@ -30,6 +30,20 @@ public class NameLiterals { WIZARD_PAGE_NAME = "Role Model", STANDARD_DIAGRAM_NAME = "newDiagram", CONTAINER_DIAGRAM_NAME = "Container"; + + /** + * name literals used for the palette categories + * <p> + * can be:<br> + * (1) the name of the palette category of entities (classes and roles)<br> + * (2) the name of the palette category of properties (attributes and operations)<br> + * (3) the name of the palette category of relations (inheritances and relationships)<br> + * (4) the name of the palette category of constraints (role, intra and inter relationship constraints) + */ + public static final String ENTITIES_PALETTE_CATEGORY_NAME = "Entities", + PROPERTIES_PALETTE_CATEGORY_NAME = "Properties", + RELATIONS_PALETTE_CATEGORY_NAME = "Relations", + CONSTRAINTS_PALETTE_CATEGORY_NAME = "Constraints"; /** * standard values for graphiti shape names and cardinalities diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/TextLiterals.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/TextLiterals.java index 6099b255f92faa1d52d8d926fc635db9b03d30ac..0f8fdc57e6f94b2d723e2904a4626490cce7ce13 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/TextLiterals.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/literals/TextLiterals.java @@ -1,8 +1,6 @@ package org.framed.iorm.ui.literals; -import org.framed.iorm.ui.exceptions.FeatureModelNotReadableException; //*import for javadoc link -import org.framed.iorm.ui.exceptions.NoDiagramFoundException; //*import for javadoc link -import org.framed.iorm.ui.exceptions.NoModelFoundException; //*import for javadoc link +import org.framed.iorm.ui.exceptions.*; //*import for javadoc link import org.framed.iorm.ui.wizards.RoleModelWizardPage; //*import for javadoc link import org.framed.iorm.ui.wizards.RoleModelWizard; //*import for javadoc link import org.eclipse.ui.PartInitException; //*import for javadoc link @@ -79,6 +77,11 @@ public class TextLiterals { */ public static final String ERROR_NO_MODEL_FOUND = "A model could not be found!"; + /** + * the message for the {@link FeatureHasNoPaletteDescriptorException} + */ + public static final String FEATURE_HAS_NO_DESCRIPTOR_MESSAGE = "A Feature has no palette descriptor: "; + /** * messages used in the Eclipse wizards * <p> diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java index a29fbbf4686c2af53dca07ebbf4693c3c518c417..ba5d160f5d0d8d14043786927efde48f04e50063 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/multipage/MultipageEditor.java @@ -29,6 +29,7 @@ import org.framed.iorm.ui.exceptions.InvalidTypeOfEditorInputException; import org.framed.iorm.ui.literals.IdentifierLiterals; import org.framed.iorm.ui.literals.NameLiterals; import org.framed.iorm.ui.literals.TextLiterals; +import org.framed.iorm.ui.palette.PaletteView; import org.framed.iorm.ui.subeditors.FRaMEDDiagramEditor; import org.framed.iorm.ui.subeditors.FRaMEDFeatureEditor; import org.framed.iorm.ui.subeditors.FRaMEDTextViewer; @@ -55,12 +56,7 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I * the identifier of the {@link DiagramTypeProvider} which is needed to instantiate an {@link DiagramEditorInput} */ private final String DIAGRAM_PROVIDER_ID = IdentifierLiterals.DIAGRAM_PROVIDER_ID; - - /** - * the palette type for a editor showing a compartments diagram gathered from {@link IdentifierLiterals} - */ - private final String PALETTE_TYPE_COMPARTMENTVIEW = IdentifierLiterals.PALETTE_TYPE_COMPARTMENTVIEW; - + /** * the value for the property diagram kind of compartment types diagram gathered from {@link IdentifierLiterals} */ @@ -242,7 +238,7 @@ public class MultipageEditor extends FormEditor implements ISelectionListener, I if(PropertyUtil.isDiagram_KindValue(diagram, DIAGRAM_KIND_COMPARTMENTTYPE_DIAGRAM)) { ToolBehaviorProvider toolBehaviorProvider = (ToolBehaviorProvider) editorDiagram.getDiagramTypeProvider().getCurrentToolBehaviorProvider(); - toolBehaviorProvider.setPaletteType(PALETTE_TYPE_COMPARTMENTVIEW); + toolBehaviorProvider.setPaletteType(PaletteView.COMPARTMENT_VIEW); editorDiagram.getDiagramBehavior().refreshPalette(); } } diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/FeatureManager.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/FeatureManager.java new file mode 100644 index 0000000000000000000000000000000000000000..520629847372e471d4be164008aa96ebac0a13b4 --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/FeatureManager.java @@ -0,0 +1,92 @@ +package org.framed.iorm.ui.palette; + +import java.util.HashMap; +import java.util.Map; + +import org.framed.iorm.ui.literals.NameLiterals; + +public class FeatureManager { + + /** + * the name literals for shape create features gathered from {@link NameLiterals} + */ + private static final String ATTRIBUTE_OPERATION_COMMON_FEATURE_NAME = NameLiterals.ATTRIBUTE_OPERATION_COMMON_FEATURE_NAME, + MODEL_FEATURE_NAME = NameLiterals.MODEL_FEATURE_NAME, + GROUP_OR_COMPARTMENT_TYPE_ELEMENT_FEATURE_NAME = NameLiterals.GROUP_OR_COMPARTMENT_TYPE_ELEMENT_FEATURE_NAME, + COMPARTMENTTYPE_FEATURE_NAME = NameLiterals.COMPARTMENTTYPE_FEATURE_NAME, + NATURALTYPE_FEATURE_NAME = NameLiterals.NATURALTYPE_FEATURE_NAME, + DATATYPE_FEATURE_NAME = NameLiterals.DATATYPE_FEATURE_NAME, + GROUP_FEATURE_NAME = NameLiterals.GROUP_FEATURE_NAME, + ROLETYPE_FEATURE_NAME = NameLiterals.ROLETYPE_FEATURE_NAME, + ATTRIBUTE_FEATURE_NAME = NameLiterals.ATTRIBUTE_FEATURE_NAME, + OPERATION_FEATURE_NAME = NameLiterals.OPERATION_FEATURE_NAME; + + /** + * the name literals for connection create features gathered from {@link NameLiterals} + */ + private static final String RELATIONSHIP_FEATURE_NAME = NameLiterals.RELATIONSHIP_FEATURE_NAME, + INHERITANCE_FEATURE_NAME = NameLiterals.INHERITANCE_FEATURE_NAME, + ROLEIMPLICATION_FEATURE_NAME = NameLiterals.ROLEIMPLICATION_FEATURE_NAME, + ROLEEQUIVALENCE_FEATURE_NAME = NameLiterals.ROLEEQUIVALENCE_FEATURE_NAME, + ROLEPROHIBITION_FEATURE_NAME = NameLiterals.ROLEPROHIBITION_FEATURE_NAME, + ACYCLIC_FEATURE_NAME = NameLiterals.ACYCLIC_FEATURE_NAME, + CYCLIC_FEATURE_NAME = NameLiterals.CYCLIC_FEATURE_NAME, + IRREFLEXIVE_FEATURE_NAME = NameLiterals.IRREFLEXIVE_FEATURE_NAME, + REFLEXIVE_FEATURE_NAME = NameLiterals.REFLEXIVE_FEATURE_NAME, + TOTAL_FEATURE_NAME = NameLiterals.TOTAL_FEATURE_NAME, + RELATIONSHIP_IMPLICATION_FEATURE_NAME = NameLiterals.RELATIONSHIP_IMPLICATION_FEATURE_NAME, + RELATIONSHIP_EXCLUSION_FEATURE_NAME = NameLiterals.RELATIONSHIP_EXCLUSION_FEATURE_NAME; + + //TODO k�rzel + private static PaletteCategory entities = PaletteCategory.ENTITIES_CATEGORY, + properties = PaletteCategory.PROPERTIES_CATEGORY, + relations = PaletteCategory.RELATIONS_CATEGORY, + constraints = PaletteCategory.CONSTRAINTS_CATEGORY, + none = PaletteCategory.NONE; + + private static ViewVisibility all = ViewVisibility.ALL_VIEWS, + top = ViewVisibility.TOPLEVEL_VIEW, + compartment = ViewVisibility.COMPARTMENT_VIEW, + no_view = ViewVisibility.NO_VIEW; + + + //TODO + public static Map<String, FeaturePaletteDescriptor> features = createFeatureCategoryMap(); + + /** + * TODO + * Step 1 features in none of the categories + * @return + */ + private static Map<String, FeaturePaletteDescriptor> createFeatureCategoryMap() { + features = new HashMap<String, FeaturePaletteDescriptor>(); + //Step 1 + features.put(ATTRIBUTE_OPERATION_COMMON_FEATURE_NAME, new FeaturePaletteDescriptor(none, no_view)); + features.put(MODEL_FEATURE_NAME, new FeaturePaletteDescriptor(none, no_view)); + features.put(GROUP_OR_COMPARTMENT_TYPE_ELEMENT_FEATURE_NAME, new FeaturePaletteDescriptor(none, no_view)); + //Step 2 + features.put(COMPARTMENTTYPE_FEATURE_NAME, new FeaturePaletteDescriptor(entities, all)); + features.put(NATURALTYPE_FEATURE_NAME, new FeaturePaletteDescriptor(entities, top)); + features.put(DATATYPE_FEATURE_NAME, new FeaturePaletteDescriptor(entities, top)); + features.put(GROUP_FEATURE_NAME, new FeaturePaletteDescriptor(entities, top)); + features.put(ROLETYPE_FEATURE_NAME, new FeaturePaletteDescriptor(entities, compartment)); + //Step 3 + features.put(ATTRIBUTE_FEATURE_NAME, new FeaturePaletteDescriptor(properties, all)); + features.put(OPERATION_FEATURE_NAME, new FeaturePaletteDescriptor(properties, all)); + //Step 4 + features.put(INHERITANCE_FEATURE_NAME, new FeaturePaletteDescriptor(relations, all)); + features.put(RELATIONSHIP_FEATURE_NAME, new FeaturePaletteDescriptor(relations, compartment)); + //Step 5 + features.put(ROLEIMPLICATION_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(ROLEEQUIVALENCE_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(ROLEPROHIBITION_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(ACYCLIC_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(CYCLIC_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(IRREFLEXIVE_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(REFLEXIVE_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(TOTAL_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(RELATIONSHIP_IMPLICATION_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + features.put(RELATIONSHIP_EXCLUSION_FEATURE_NAME, new FeaturePaletteDescriptor(constraints, compartment)); + return features; + } +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/FeaturePaletteDescriptor.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/FeaturePaletteDescriptor.java new file mode 100644 index 0000000000000000000000000000000000000000..f0ffdf211a72ba216f8505b51836f6b65813079e --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/FeaturePaletteDescriptor.java @@ -0,0 +1,13 @@ +package org.framed.iorm.ui.palette; + +public class FeaturePaletteDescriptor { + + public PaletteCategory paletteCategory = PaletteCategory.NONE; + public ViewVisibility viewVisibility = ViewVisibility.NO_VIEW; + + public FeaturePaletteDescriptor(PaletteCategory paletteCategory, ViewVisibility viewVisibility) { + this.paletteCategory = paletteCategory; + this.viewVisibility = viewVisibility; + } + +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/PaletteCategory.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/PaletteCategory.java new file mode 100644 index 0000000000000000000000000000000000000000..20f776408eece0c78393727a7ebe913d642e5397 --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/PaletteCategory.java @@ -0,0 +1,11 @@ +package org.framed.iorm.ui.palette; + +public enum PaletteCategory { + + ENTITIES_CATEGORY, + PROPERTIES_CATEGORY, + RELATIONS_CATEGORY, + CONSTRAINTS_CATEGORY, + NONE; + +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/PaletteView.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/PaletteView.java new file mode 100644 index 0000000000000000000000000000000000000000..fc74c8caba9f207be0e5f8aab4d0ecb9c33b16c4 --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/PaletteView.java @@ -0,0 +1,8 @@ +package org.framed.iorm.ui.palette; + +public enum PaletteView { + + TOPLEVEL_VIEW, + COMPARTMENT_VIEW; + +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/ViewVisibility.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/ViewVisibility.java new file mode 100644 index 0000000000000000000000000000000000000000..d91966e2da2992fa676b64ac537574868d5c5ef3 --- /dev/null +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/palette/ViewVisibility.java @@ -0,0 +1,10 @@ +package org.framed.iorm.ui.palette; + +public enum ViewVisibility { + + ALL_VIEWS, + TOPLEVEL_VIEW, + COMPARTMENT_VIEW, + NO_VIEW; + +} diff --git a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java index 865d5d15626278c14187dcfdef7178300e6e4ff1..4a24b62c1af06c786bd115e61da2706806207bf8 100644 --- a/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java +++ b/org.framed.iorm.ui/src/org/framed/iorm/ui/providers/ToolBehaviorProvider.java @@ -5,6 +5,8 @@ import java.util.List; import org.eclipse.emf.ecore.EObject; import org.eclipse.graphiti.dt.IDiagramTypeProvider; +import org.eclipse.graphiti.features.ICreateConnectionFeature; +import org.eclipse.graphiti.features.ICreateFeature; import org.eclipse.graphiti.features.context.ICustomContext; import org.eclipse.graphiti.features.context.IPictogramElementContext; import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; @@ -13,18 +15,24 @@ import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.palette.IPaletteCompartmentEntry; -import org.eclipse.graphiti.palette.IToolEntry; +import org.eclipse.graphiti.palette.impl.ConnectionCreationToolEntry; +import org.eclipse.graphiti.palette.impl.ObjectCreationToolEntry; +import org.eclipse.graphiti.palette.impl.PaletteCompartmentEntry; import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IContextButtonPadData; import org.eclipse.graphiti.tb.IContextMenuEntry; import org.framed.iorm.ui.literals.IdentifierLiterals; import org.framed.iorm.ui.literals.NameLiterals; +import org.framed.iorm.ui.palette.FeatureManager; +import org.framed.iorm.ui.palette.FeaturePaletteDescriptor; +import org.framed.iorm.ui.palette.PaletteView; +import org.framed.iorm.ui.palette.ViewVisibility; import org.framed.iorm.ui.util.DiagramUtil; -import org.framed.iorm.ui.util.GeneralUtil; import org.framed.iorm.ui.util.PropertyUtil; import org.framed.iorm.ui.providers.FeatureProvider; //*import for javadoc link import org.framed.iorm.model.Relation; import org.framed.iorm.model.Type; +import org.framed.iorm.ui.exceptions.FeatureHasNoPaletteDescriptorException; import org.framed.iorm.ui.graphitifeatures.StepInFeature; //*import for javadoc link import org.framed.iorm.ui.graphitifeatures.StepInNewTabFeature; //*import for javadoc link import org.framed.iorm.ui.graphitifeatures.StepOutFeature; //*import for javadoc link @@ -34,35 +42,15 @@ import org.framed.iorm.ui.graphitifeatures.StepOutFeature; //*import for javadoc * @author Kevin Kassin */ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{ - + /** - * the name literals for shape create features to remove from the editor palette for the diagram type - * gathered from {@link NameLiterals} + * names for the palette categories gathered from {@link NameLiterals} */ - private final String ATTRIBUTE_OPERATION_COMMON_FEATURE_NAME = NameLiterals.ATTRIBUTE_OPERATION_COMMON_FEATURE_NAME, - MODEL_FEATURE_NAME = NameLiterals.MODEL_FEATURE_NAME, - GROUP_OR_COMPARTMENT_TYPE_ELEMENT_FEATURE_NAME = NameLiterals.GROUP_OR_COMPARTMENT_TYPE_ELEMENT_FEATURE_NAME, - NATURALTYPE_FEATURE_NAME = NameLiterals.NATURALTYPE_FEATURE_NAME, - DATATYPE_FEATURE_NAME = NameLiterals.DATATYPE_FEATURE_NAME, - GROUP_FEATURE_NAME = NameLiterals.GROUP_FEATURE_NAME, - ROLETYPE_FEATURE_NAME = NameLiterals.ROLETYPE_FEATURE_NAME; - - /** - * the name literals for connection create features to remove from the editor palette for the diagram type - * gathered from {@link NameLiterals} - */ - private final String ROLEIMPLICATION_FEATURE_NAME = NameLiterals.ROLEIMPLICATION_FEATURE_NAME, - ROLEEQUIVALENCE_FEATURE_NAME = NameLiterals.ROLEEQUIVALENCE_FEATURE_NAME, - ROLEPROHIBITION_FEATURE_NAME = NameLiterals.ROLEPROHIBITION_FEATURE_NAME, - RELATIONSHIP_FEATURE_NAME = NameLiterals.RELATIONSHIP_FEATURE_NAME, - RELATIONSHIP_DECORATOR_FEATURE_NAME = NameLiterals.RELATIONSHIP_DECORATOR_FEATURE_NAME, - ACYCLIC_FEATURE_NAME = NameLiterals.ACYCLIC_FEATURE_NAME, - CYCLIC_FEATURE_NAME = NameLiterals.CYCLIC_FEATURE_NAME, - IRREFLEXIVE_FEATURE_NAME = NameLiterals.IRREFLEXIVE_FEATURE_NAME, - REFLEXIVE_FEATURE_NAME = NameLiterals.REFLEXIVE_FEATURE_NAME, - TOTAL_FEATURE_NAME = NameLiterals.TOTAL_FEATURE_NAME, - RELATIONSHIP_IMPLICATION_FEATURE_NAME = NameLiterals.RELATIONSHIP_IMPLICATION_FEATURE_NAME, - RELATIONSHIP_EXCLUSION_FEATURE_NAME = NameLiterals.RELATIONSHIP_EXCLUSION_FEATURE_NAME; + private final String ENTITIES_PALETTE_CATEGORY_NAME = NameLiterals.ENTITIES_PALETTE_CATEGORY_NAME, + PROPERTIES_PALETTE_CATEGORY_NAME = NameLiterals.PROPERTIES_PALETTE_CATEGORY_NAME, + RELATIONS_PALETTE_CATEGORY_NAME = NameLiterals.RELATIONS_PALETTE_CATEGORY_NAME, + CONSTRAINTS_PALETTE_CATEGORY_NAME = NameLiterals.CONSTRAINTS_PALETTE_CATEGORY_NAME; + /** * the value for the property diagram kind to identify diagrams belonging to a group or compartment type gathered * from {@link IdentiferLiterals} @@ -90,62 +78,34 @@ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{ private final String SHAPE_ID_GROUP_TYPEBODY = IdentifierLiterals.SHAPE_ID_GROUP_TYPEBODY, SHAPE_ID_COMPARTMENTTYPE_TYPEBODY = IdentifierLiterals.SHAPE_ID_COMPARTMENTTYPE_TYPEBODY; - /** - * identifiers used to differ the types of palettes gathered from {@link IdentifierLiterals} - */ - private final String PALETTE_TYPE_TOPLEVELVIEW = IdentifierLiterals.PALETTE_TYPE_TOPLEVELVIEW, - PALETTE_TYPE_COMPARTMENTVIEW = IdentifierLiterals.PALETTE_TYPE_COMPARTMENTVIEW; - /** * the current type of the palette of the editor * <p> * This attribute is set by the {@link StepInFeature}, {@link StepInNewTabFeature} and {@link StepOutFeature}. * It is used to calculate the palette element to display depending on the type of diagram the editor is showing. */ - private String paletteType = PALETTE_TYPE_TOPLEVELVIEW; - - private List<String> createFeaturesToHideInEveryView = new ArrayList<String>(), - createFeaturesToHideInTopLevelView = new ArrayList<String>(), - createFeaturesToHideInCompartmentView = new ArrayList<String>(); + private PaletteView paletteView = PaletteView.TOPLEVEL_VIEW; + //TODO + PaletteCompartmentEntry entityCategory = new PaletteCompartmentEntry(ENTITIES_PALETTE_CATEGORY_NAME, null); + PaletteCompartmentEntry propertiesCategory = new PaletteCompartmentEntry(PROPERTIES_PALETTE_CATEGORY_NAME, null); + PaletteCompartmentEntry relationsCategory = new PaletteCompartmentEntry(RELATIONS_PALETTE_CATEGORY_NAME, null); + PaletteCompartmentEntry constraintsCategory = new PaletteCompartmentEntry(CONSTRAINTS_PALETTE_CATEGORY_NAME, null); + /** * Class constructor - * <p> - * fills the list of features to hide * @param diagramTypeProvider the provider of the edited diagram type */ public ToolBehaviorProvider(IDiagramTypeProvider diagramTypeProvider) { super(diagramTypeProvider); - //features to hide in every view - createFeaturesToHideInEveryView.add(ATTRIBUTE_OPERATION_COMMON_FEATURE_NAME); - createFeaturesToHideInEveryView.add(MODEL_FEATURE_NAME); - createFeaturesToHideInEveryView.add(GROUP_OR_COMPARTMENT_TYPE_ELEMENT_FEATURE_NAME); - createFeaturesToHideInEveryView.add(RELATIONSHIP_DECORATOR_FEATURE_NAME); - //features to hide in the top level view - createFeaturesToHideInTopLevelView.add(ROLEIMPLICATION_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(ROLEEQUIVALENCE_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(ROLEPROHIBITION_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(RELATIONSHIP_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(ROLETYPE_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(ACYCLIC_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(CYCLIC_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(IRREFLEXIVE_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(REFLEXIVE_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(TOTAL_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(RELATIONSHIP_IMPLICATION_FEATURE_NAME); - createFeaturesToHideInTopLevelView.add(RELATIONSHIP_EXCLUSION_FEATURE_NAME); - //feature to hide in the compartment view - createFeaturesToHideInCompartmentView.add(NATURALTYPE_FEATURE_NAME); - createFeaturesToHideInCompartmentView.add(DATATYPE_FEATURE_NAME); - createFeaturesToHideInCompartmentView.add(GROUP_FEATURE_NAME); } /** - * sets the value of the palette type to be shown - * @param paletteType the new palette to be set + * sets the value of the palette view to be shown + * @param paletteType the new palette view to be set */ - public void setPaletteType(String paletteType) { - this.paletteType = paletteType; + public void setPaletteType(PaletteView paletteView) { + this.paletteView = paletteView; } /** @@ -236,53 +196,89 @@ public class ToolBehaviorProvider extends DefaultToolBehaviorProvider{ } /** - * removes create features implemented by the pattern from the palette using the following steps: + * builds the palette of the editor using the following steps * <p> - * Step 1: It hides patterns that dont have a create features or whichs create features should not be used by the user - * manually. - * Step 2: It hides patterns that should not be shown if the palette type of the provider is set to class palette.<br> - * Step 3: It hides patterns that should not be shown if the palette type of the provider is set to role palette. + * Step 1: It creates the different palette categories.<br> + * Step 2: It add create shape features to the correct categories according to the {@link FeatureManager} */ @Override public IPaletteCompartmentEntry[] getPalette() { - List<IPaletteCompartmentEntry> paletteCompartmentEntry = new ArrayList<IPaletteCompartmentEntry>(); - List<IToolEntry> toolEntriesShapesToDelete = new ArrayList<IToolEntry>(); - List<IToolEntry> toolEntriesConnectionToDelete = new ArrayList<IToolEntry>(); - IPaletteCompartmentEntry[] superCompartments = super.getPalette(); - //Step 1 - for(int i = 0; i < superCompartments[1].getToolEntries().size(); i++) { - IToolEntry toolEntry = superCompartments[1].getToolEntries().get(i); - if(GeneralUtil.containsEqual(createFeaturesToHideInEveryView, toolEntry.getLabel())) - toolEntriesShapesToDelete.add(toolEntry); - } - //Step 2 - if(paletteType.equals(PALETTE_TYPE_TOPLEVELVIEW)) { - for(int i = 0; i < superCompartments[0].getToolEntries().size(); i++) { - IToolEntry toolEntry = superCompartments[0].getToolEntries().get(i); - if(GeneralUtil.containsEqual(createFeaturesToHideInTopLevelView, toolEntry.getLabel())) - toolEntriesConnectionToDelete.add(toolEntry); - } - for(int i = 0; i < superCompartments[1].getToolEntries().size(); i++) { - IToolEntry toolEntry = superCompartments[1].getToolEntries().get(i); - if(GeneralUtil.containsEqual(createFeaturesToHideInTopLevelView, toolEntry.getLabel())) - toolEntriesShapesToDelete.add(toolEntry); - } } - //Step 3 - if(paletteType.equals(PALETTE_TYPE_COMPARTMENTVIEW)) { - for(int i = 0; i < superCompartments[1].getToolEntries().size(); i++) { - IToolEntry toolEntry = superCompartments[1].getToolEntries().get(i); - if(GeneralUtil.containsEqual(createFeaturesToHideInCompartmentView, toolEntry.getLabel())) - toolEntriesShapesToDelete.add(toolEntry); - } } - for(IToolEntry toolEntryConnectionToDelete : toolEntriesConnectionToDelete) { - superCompartments[0].getToolEntries().remove(toolEntryConnectionToDelete); - } - for(IToolEntry toolEntryShapeToDelete : toolEntriesShapesToDelete) { - superCompartments[1].getToolEntries().remove(toolEntryShapeToDelete); - } - for (int j = 0; j < superCompartments.length; j++) { - paletteCompartmentEntry.add(superCompartments[j]); - } - return paletteCompartmentEntry.toArray(new IPaletteCompartmentEntry[paletteCompartmentEntry.size()]); + List<IPaletteCompartmentEntry> pallete = new ArrayList<IPaletteCompartmentEntry>(); + //Step 1 + entityCategory = new PaletteCompartmentEntry(ENTITIES_PALETTE_CATEGORY_NAME, null); + propertiesCategory = new PaletteCompartmentEntry(PROPERTIES_PALETTE_CATEGORY_NAME, null); + relationsCategory = new PaletteCompartmentEntry(RELATIONS_PALETTE_CATEGORY_NAME, null); + constraintsCategory = new PaletteCompartmentEntry(CONSTRAINTS_PALETTE_CATEGORY_NAME, null); + for(ICreateFeature feature : getFeatureProvider().getCreateFeatures()) { + addShapeFeature(feature); + } + for(ICreateConnectionFeature feature : getFeatureProvider().getCreateConnectionFeatures()) { + addConnectionFeature(feature); + } + pallete.add(entityCategory); + pallete.add(propertiesCategory); + pallete.add(relationsCategory); + pallete.add(constraintsCategory); + return pallete.toArray(new IPaletteCompartmentEntry[pallete.size()]); } + + private void addShapeFeature(ICreateFeature feature) { + FeaturePaletteDescriptor fpd = FeatureManager.features.get(feature.getCreateName()); + if(fpd == null) throw new FeatureHasNoPaletteDescriptorException(feature.getCreateName()); + if((fpd.viewVisibility == ViewVisibility.ALL_VIEWS) || + (paletteView == PaletteView.TOPLEVEL_VIEW && + fpd.viewVisibility == ViewVisibility.TOPLEVEL_VIEW) || + (paletteView == PaletteView.COMPARTMENT_VIEW && + fpd.viewVisibility == ViewVisibility.COMPARTMENT_VIEW)) { + ObjectCreationToolEntry objectCreationToolEntry = + new ObjectCreationToolEntry( feature.getCreateName(), + feature.getCreateDescription(), feature.getCreateImageId(), + feature.getCreateLargeImageId(), feature); + switch(fpd.paletteCategory) { + case ENTITIES_CATEGORY: + entityCategory.addToolEntry(objectCreationToolEntry); + break; + case PROPERTIES_CATEGORY: + propertiesCategory.addToolEntry(objectCreationToolEntry); + break; + case RELATIONS_CATEGORY: + relationsCategory.addToolEntry(objectCreationToolEntry); + break; + case CONSTRAINTS_CATEGORY: + constraintsCategory.addToolEntry(objectCreationToolEntry); + break; + default: + break; + } } } + + private void addConnectionFeature(ICreateConnectionFeature feature) { + FeaturePaletteDescriptor fpd = FeatureManager.features.get(feature.getCreateName()); + if(fpd == null) throw new FeatureHasNoPaletteDescriptorException(feature.getCreateName()); + if((fpd.viewVisibility == ViewVisibility.ALL_VIEWS) || + (paletteView == PaletteView.TOPLEVEL_VIEW && + fpd.viewVisibility == ViewVisibility.TOPLEVEL_VIEW) || + (paletteView == PaletteView.COMPARTMENT_VIEW && + fpd.viewVisibility == ViewVisibility.COMPARTMENT_VIEW)) { + ConnectionCreationToolEntry connectionCreationToolEntry = + new ConnectionCreationToolEntry(feature.getCreateName(), + feature.getCreateDescription(), feature.getCreateImageId(), + feature.getCreateLargeImageId()); + connectionCreationToolEntry.addCreateConnectionFeature(feature); + switch(fpd.paletteCategory) { + case ENTITIES_CATEGORY: + entityCategory.addToolEntry(connectionCreationToolEntry); + break; + case PROPERTIES_CATEGORY: + propertiesCategory.addToolEntry(connectionCreationToolEntry); + break; + case RELATIONS_CATEGORY: + relationsCategory.addToolEntry(connectionCreationToolEntry); + break; + case CONSTRAINTS_CATEGORY: + constraintsCategory.addToolEntry(connectionCreationToolEntry); + break; + default: + break; + } } } } +