Class AbstractPattern

    • Field Detail

      • EMPTY_STRING_ARRAY

        protected static final java.lang.String[] EMPTY_STRING_ARRAY
        An empty string array used in direct editing.
    • Constructor Detail

      • AbstractPattern

        public AbstractPattern​(IPatternConfiguration patternConfiguration)
        Creates a new AbstractPattern holding the given IPatternConfiguration.
        Parameters:
        patternConfiguration - The pattern configuration to use within this pattern instance of null in case no configuration is needed.
      • AbstractPattern

        public AbstractPattern()
        Creates a new AbstractPattern. This is a convenience method for patterns working without any configuration.
        Since:
        0.10
    • Method Detail

      • isPaletteApplicable

        public boolean isPaletteApplicable()
        Is queried by the Graphiti framework to check if the pattern should create a new domain object entry in the editor palette.
        Specified by:
        isPaletteApplicable in interface IPattern
        Returns:
        true in case a palette entry shall be created, false otherwise.
      • canCreate

        public boolean canCreate​(ICreateContext context)
        Clients must override this method to indicate that the pattern can be used to create domain objects as defined in the given ICreateContext. Corresponds to the method ICreate.canCreate(ICreateContext) . The default implementation simply returns false.
        Specified by:
        canCreate in interface ICreate
        Parameters:
        context - The context holding information on the domain object to be created.
        Returns:
        true in case this pattern can create such a domain object, false otherwise.
      • create

        public java.lang.Object[] create​(ICreateContext context)
        Clients must override this method to implement the functionality to create a new domain object as defined in the given ICreateContext . Corresponds to the method ICreate.create(ICreateContext). The default implementation simply does nothing and returns an empty object array.
        Specified by:
        create in interface ICreate
        Parameters:
        context - The context holding information on the domain object to be created.
        Returns:
        An array of the newly create domain objects.
      • getCreateDescription

        public java.lang.String getCreateDescription()
        Client should override to return a string description of the type of domain object that is created with this pattern. The Graphiti framework uses this information to fill a tooltip for the creation tool entry in the palette. The default implementation simply returns null which indicates that no tooltip shall be displayed.
        Specified by:
        getCreateDescription in interface ICreateInfo
        Specified by:
        getCreateDescription in interface IPattern
        Returns:
        A String holding the tooltip
      • getCreateImageId

        public java.lang.String getCreateImageId()
        Client should override to return a string id of the the image icon for the domain object that is created with this pattern. The Graphiti framework uses this information to add an icon to the creation tool entry in the palette. The default implementation simply returns null which indicates that no icon shall be displayed.
        Specified by:
        getCreateImageId in interface ICreateInfo
        Returns:
        A String holding the id of the icon as defined in the AbstractImageProvider.
      • getCreateLargeImageId

        public java.lang.String getCreateLargeImageId()
        Client should override to return a string id of the the large image icon for the domain object that is created with this pattern. The Graphiti framework uses this information to add a large icon to the creation tool entry in the palette. The default implementation simply returns null which indicates that no icon shall be displayed.
        Specified by:
        getCreateLargeImageId in interface ICreateInfo
        Returns:
        A String holding the id of the large icon as defined in the AbstractImageProvider.
      • getCreateName

        public java.lang.String getCreateName()
        Client should override to return the name of the domain object that is created with this pattern. The Graphiti framework uses this information to fill the text for the creation tool entry in the palette. The default implementation simply returns null which results in an empty entry in the palette.
        Specified by:
        getCreateName in interface ICreateInfo
        Specified by:
        getCreateName in interface IPattern
        Returns:
        A String holding the name of the domain object.
      • isMainBusinessObjectApplicable

        public abstract boolean isMainBusinessObjectApplicable​(java.lang.Object mainBusinessObject)
        Clients must override this method to indicate that the pattern uses the given domain object as its main domain object.
        Specified by:
        isMainBusinessObjectApplicable in interface IPattern
        Parameters:
        mainBusinessObject - The object to check if it is the main domain object of the pattern.
        Returns:
        true in case the pattern has the given domain object as its main domain object, false otherwise.
      • layout

        public boolean layout​(ILayoutContext context)
        Clients can override this method to implement the functionality to layout a shape for the given domain object as defined in the given ILayoutContext . Corresponds to the method ILayout.layout(ILayoutContext). The default implementation simply does nothing and returns false as indication of this.
        Specified by:
        layout in interface ILayout
        Parameters:
        context - The context holding information on the domain object to be layouted.
        Returns:
        Should return true in case a layout happened and false in case none happened. Is used by the Graphiti framework for performance optimization.
      • postMoveShape

        protected void postMoveShape​(IMoveShapeContext context)
        Hook clients can override to add additional steps after the move of the shape happened.
        Parameters:
        context - The context holding information on the domain object that was moved.
      • preMoveShape

        protected void preMoveShape​(IMoveShapeContext context)
        Hook clients can override to add additional steps before the move of the shape happens.
        Parameters:
        context - The context holding information on the domain object to be moved.
      • internalMove

        protected void internalMove​(IMoveShapeContext context)
        Default implementation of the move functionality. Moves shapes to new coordinates and adapts parents in case this is needed.
        Parameters:
        context - The context holding information on the domain object to be moved.
      • moveAllBendpoints

        protected void moveAllBendpoints​(IMoveShapeContext context)
        Default implementation of the move functionality to move all bendpoints within a container shape.
        Parameters:
        context - The context holding information on the domain object to be moved.
      • update

        public boolean update​(IUpdateContext context)
        Clients can override this method to implement the functionality to update a shape for the given domain object as defined in the given IUpdateContext. Corresponds to the method IUpdate.update(IUpdateContext).
        Specified by:
        update in interface IUpdate
        Parameters:
        context - The context holding information on the domain object to be updated.
        Returns:
        true, if update process was successfull
      • updateNeeded

        public IReason updateNeeded​(IUpdateContext context)
        Clients can override this method to indicate if an update of a shape for the given domain object as defined in the given IUpdateContext needs to be triggered. Corresponds to the method IUpdate.updateNeeded(IUpdateContext).
        Specified by:
        updateNeeded in interface IUpdate
        Parameters:
        context - The context holding information on the domain object to be updated.
        Returns:
        true if parts of the pictogram model needs to be updated with the latest values from the business model
      • addGraphicalRepresentation

        protected void addGraphicalRepresentation​(IAreaContext context,
                                                  java.lang.Object newObject)
        Adds the graphical representation of the given new Object with the information in the given IAreaContext.
        Parameters:
        context - The area context defining where the new object should placed
        newObject - The new object instance itself
      • avoidNegativeCoordinates

        protected boolean avoidNegativeCoordinates()
        Clients can override to indicate that moving to negative coordinates should be possible. The default implementation prohibits this by returning false.
        Returns:
        true in case moving a shape to negative coordinates should be possible, false otherwise.
      • isPatternControlled

        protected abstract boolean isPatternControlled​(PictogramElement pictogramElement)
        This method must be implemented by clients to indicate that the given PictogramElement is controlled by this pattern.
        Parameters:
        pictogramElement - The pictogram element to check
        Returns:
        true in case the pictogram element is controlled by this pattern, false otherwise.
      • isPatternRoot

        protected abstract boolean isPatternRoot​(PictogramElement pictogramElement)
        This method must be implemented by clients to indicate that the given PictogramElement is the root shape of this pattern.
        Parameters:
        pictogramElement - The pictogram element to check
        Returns:
        true in case the pictogram element is the root shape of this pattern, false otherwise.
      • layoutPictogramElement

        protected void layoutPictogramElement​(PictogramElement pe)
        Helper method that triggers a layout of the given PictogramElement. The default implementation queries the feature provider and tries to find a functionality either in the pattern of an additional AbstractLayoutFeature that can handle the request and triggers the operation.
        Parameters:
        pe - The pictogram element to layout
      • updatePictogramElement

        protected void updatePictogramElement​(PictogramElement pe)
        Helper method that triggers an update of the given PictogramElement. The default implementation queries the feature provider and tries to find a functionality either in the pattern of an additional AbstractUpdateFeature that can handle the request and triggers the operation.
        Parameters:
        pe - The pictogram element to update
      • setPatternConfiguration

        protected void setPatternConfiguration​(IPatternConfiguration patternConfiguration)
        Sets the IPatternConfiguration instance to be used with this pattern.
        Parameters:
        patternConfiguration - The new patternConfiguration
      • getPatternConfiguration

        protected IPatternConfiguration getPatternConfiguration()
        Returns the IPatternConfiguration instance used within this pattern or null in case none is used.
        Returns:
        The patternConfiguration instance or null it there is none set
      • completeInfo

        public void completeInfo​(IDirectEditingInfo info,
                                 java.lang.Object bo)
        Clients can override to complete the IDirectEditingInfo info. This information is needed to switch automatically into the direct editing mode. (e.g. after creation of a new object).
        Specified by:
        completeInfo in interface IPattern
        Parameters:
        info - The direct editing info
        bo - The domain object
      • completeInfo

        public void completeInfo​(IDirectEditingInfo info,
                                 java.lang.Object bo,
                                 java.lang.String keyProperty)
        Clients can override to complete the IDirectEditingInfo info. This information is needed to switch automatically into the direct editing mode. (e.g. after creation of a new object)
        Specified by:
        completeInfo in interface IPattern
        Parameters:
        info - The direct editing info
        bo - The domain object
        keyProperty - The key property
      • canDelete

        public boolean canDelete​(IDeleteContext context)
        Clients can override to modify the default behavior if the pattern can (and wants to) handle a delete request. The default implementation calls createDeleteFeature(IDeleteContext) and asks the result's canDelete method.
        Specified by:
        canDelete in interface IDelete
        Parameters:
        context - The context describing the delete request
        Returns:
        true, if the pattern can perform the delete operation, false otherwise
      • preDelete

        public void preDelete​(IDeleteContext context)
        Clients can override to add actions before the default delete behavior is triggered. The default implementation does nothing and is called from the registered delete feature.
        Specified by:
        preDelete in interface IDelete
        Parameters:
        context - The context describing the delete request
      • delete

        public void delete​(IDeleteContext context)
        Clients can override to modify the default delete behavior. The default implementation calls createDeleteFeature(IDeleteContext) and triggers the result's delete method.
        Specified by:
        delete in interface IDelete
        Parameters:
        context - The context describing the delete request
      • postDelete

        public void postDelete​(IDeleteContext context)
        Clients can override to add actions after the default delete behavior is triggered. The default implementation does nothing and is called from the registered delete feature.
        Specified by:
        postDelete in interface IDelete
        Parameters:
        context - The context describing the delete request
      • canRemove

        public boolean canRemove​(IRemoveContext context)
        Clients can override to modify the default behavior if the pattern can (and wants to) handle a remove request. The default implementation calls createRemoveFeature(IRemoveContext) and asks the result's canRemove method.
        Specified by:
        canRemove in interface IRemove
        Parameters:
        context - The context describing the remove request
        Returns:
        true, if the pattern can perform the delete operation, false otherwise
      • preRemove

        public void preRemove​(IRemoveContext context)
        Clients can override to add actions before the default remove behavior is triggered. The default implementation does nothing and is called from the registered remove feature.
        Specified by:
        preRemove in interface IRemove
        Parameters:
        context - The context describing the remove request
      • remove

        public void remove​(IRemoveContext context)
        Clients can override to modify the default remove behavior. The default implementation calls createRemoveFeature(IRemoveContext) and triggers the result's remove method.
        Specified by:
        remove in interface IRemove
        Parameters:
        context - The context describing the remove request
      • postRemove

        public void postRemove​(IRemoveContext context)
        Clients can override to add actions after the default remove behavior is triggered. The default implementation does nothing and is called from the registered remove feature.
        Specified by:
        postRemove in interface IRemove
        Parameters:
        context - The context describing the remove request
      • checkValueValid

        public java.lang.String checkValueValid​(java.lang.String value,
                                                IDirectEditingContext context)
        This method will be called by the framework to check if the passed String is valid as new value for the shape. This method's response time should be small since the method is queried after each change of the value in the direct edit UI. The default implementation simply returns null to indicate that all values are valid. In case of a not valid value, the returned string shall indicate the reason why the value is not valid. Corresponds to the method AbstractDirectEditingFeature.checkValueValid(String, IDirectEditingContext) .
        Specified by:
        checkValueValid in interface IDirectEditing
        Parameters:
        value - The new value to check
        context - A context object describing the direct edit request.
        Returns:
        null in case of a valid value, a string describing the reason for being not valid otherwise.
      • completeValue

        public java.lang.String completeValue​(java.lang.String value,
                                              int caretPos,
                                              java.lang.String chosenValue,
                                              IDirectEditingContext context)
        Can be overridden by clients to define completion functionality for direct editing. Corresponds to AbstractDirectEditingFeature.completeValue(String, int, String, IDirectEditingContext) . The default implementation simply returns the parameter chosenValue.
        Specified by:
        completeValue in interface IDirectEditing
        Parameters:
        value - The current value
        caretPosition - The current cursor position
        choosenValue - The value chosen by user
        context - A context object describing the direct edit request.
        Returns:
        The new value
      • getValueProposals

        public java.lang.String[] getValueProposals​(java.lang.String value,
                                                    int caretPos,
                                                    IDirectEditingContext context)
        This proposals will be used for the completion list of a simple text cell editor. This functionality only applies to TYPE_TEXT. Corresponds to the method AbstractDirectEditingFeature.getValueProposals(String, int, IDirectEditingContext) . The default implementation returns an empty string array.
        Specified by:
        getValueProposals in interface IDirectEditing
        Parameters:
        value - The current value
        caretPosition - The current cursor position
        context - A context object describing the direct edit request.
        Returns:
        The proposed values
      • stretchFieldToFitText

        public boolean stretchFieldToFitText()
        Defines if the input field should be streched to fit its contents. This functionality applies to TYPE_TEXT, TYPE_DROPDOWN and TYPE_DROPDOWN_READ_ONLY. Corresponds to method AbstractDirectEditingFeature.stretchFieldToFitText(). The default implementation simply returns false.
        Specified by:
        stretchFieldToFitText in interface IDirectEditing
        Returns:
        true if the field should exactly fit the contents, false otherwise.
      • getInitialValue

        public java.lang.String getInitialValue​(IDirectEditingContext context)
        Provides the initial value for display in the newly opened text editing UI component. Corresponds to the method IDirectEditing.getInitialValue(IDirectEditingContext) . The default implementation always returns an empty string.
        Specified by:
        getInitialValue in interface IDirectEditing
        Parameters:
        context - A context object describing the direct edit request.
        Returns:
        The initial string value to be displayed for editing by the user.
      • getProposalSupport

        public IProposalSupport getProposalSupport()
        The direct editing mode contains controls for code completion and the selection from a combo box. In both cases the standard implementation supports only strings.

        If the client wants to work with Objects he must provide an implementation of IProposalSupport. In this case the following methods of the pattern are ignored:


        * String checkValueValid(String value, IDirectEditingContext context);
        * String completeValue(String value, int caretPosition, String choosenValue, IDirectEditingContext context);
        * String[] getPossibleValues(IDirectEditingContext context);
        * String[] getValueProposals(String value, int caretPosition, IDirectEditingContext context);
        * void setValue(String value, IDirectEditingContext context);

        Corresponds to the method AbstractDirectEditingFeature.getProposalSupport(). The default implementation returns null to enable the standard string-based direct editing functionality.

        Specified by:
        getProposalSupport in interface IDirectEditing
        Returns:
        The special implementation to support Objects in code completion and combo box
        Since:
        0.8
      • hasDoneChanges

        public boolean hasDoneChanges​(java.lang.Class<?> actionType)
        Is queried by the framework after a pattern has been executed to find out if this pattern should appear in the undo stack. By default all patterns should appear there (see implementation in AbstractPattern), but single pattern functionality may decide to override this behavior. Note that this is a dynamic attribute of the pattern that is queried each time after the pattern functionality has been executed.

        IMPORTANT NOTE: The implementor of the feature is responsible for correctly implementing this method! It will lead to inconsistencies if this method returns false although the pattern did changes.

        Specified by:
        hasDoneChanges in interface IPattern
        Parameters:
        actionType - the followings types are currently supported: IDelete.class, IRemove.class
        Returns:
        true if the last action of the pattern from this action type should appear in the undo stack, false otherwise
        Since:
        0.9
      • isDeleteAbort

        public boolean isDeleteAbort()
        Description copied from interface: IDelete
        The Graphiti framework will call this method after IDelete.preDelete(IDeleteContext) has been called and before the actual delete is done. In case this method returns true, the operation will be cancelled by the Graphiti framework by throwing an OperationCanceledException that causes am EMF revert of the operation.

        Implementing classes might e.g. set a flag in IDelete.preDelete(IDeleteContext) as cancellation indication and check that that flag here.

        Specified by:
        isDeleteAbort in interface IDelete
        Returns:
        true in case you want to cancel the current operation, false otherwise.
        Since:
        0.12
      • isRemoveAbort

        public boolean isRemoveAbort()
        Description copied from interface: IRemove
        The Graphiti framework will call this method after IRemove.preRemove(IRemoveContext) has been called and before the actual remove is done. In case this method returns true, the operation will be cancelled by the Graphiti framework by throwing an OperationCanceledException that causes am EMF revert of the operation.

        Implementing classes might e.g. set a flag in IRemove.preRemove(IRemoveContext) as cancellation indication and check that that flag here.

        Specified by:
        isRemoveAbort in interface IRemove
        Returns:
        true in case you want to cancel the current operation, false otherwise.
        Since:
        0.12