Class PropHelper


  • public class PropHelper
    extends java.lang.Object
    Helper class for properties.
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static java.lang.ObjectMANY_VALUES
      Special object returned for getCommonValue() when many different values exist.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      PropHelper() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and TypeMethodDescription
      static voidaddUndoContext​(GProp<?> gp, org.eclipse.core.commands.operations.IUndoableOperation operation)
      Adds the undo contexts from a property to an operation.
      static voidaddUndoContexts​(GProp<?>[] props, org.eclipse.core.commands.operations.IUndoableOperation operation)
      Adds the undo contexts from a property to an operation.
      static java.lang.String[]autoRename​(PropCnr target, GProp<?>[] props, java.lang.String first, java.lang.String next, java.lang.String next2)
      Auto-renames properties.
      static java.lang.StringcanPerform​(GProp<?>[] props, int operation)
      Checks properties for a valid operation.
      static java.lang.StringcanPerform​(java.util.ArrayList<DesignerProp> list, int operation)
      Checks properties for a valid operation.
      static java.lang.StringdoAdd​(java.lang.String description, PropCnr target, GProp<?>[] props, IPropUndoRedo undoRedo, boolean doAutoRename)
      Adds properties with undo/redo support.
      static java.lang.StringdoAdd​(java.lang.String description, PropCnr target, GProp<?> prop, IPropUndoRedo undoRedo, boolean doAutoRename)
      Adds a property with undo/redo support.
      static voiddoCopy​(org.eclipse.swt.widgets.Shell parent, org.eclipse.jface.viewers.ISelection selection, java.lang.Runnable completeCallback)
      Performs the Copy operation.
      static java.lang.StringdoCut​(org.eclipse.jface.viewers.ISelection selection, IPropUndoRedo undoRedo, java.lang.Runnable completeCallback)
      Cuts the selection in a viewer.
      static java.lang.StringdoDelete​(java.lang.String description, GProp<?>[] props, IPropUndoRedo undoRedo, java.lang.Runnable completeCallback)
      Performs a delete of pure properties (cannot be resource based).
      static java.lang.StringdoDelete​(org.eclipse.jface.viewers.ISelection selection, IPropUndoRedo undoRedo, java.lang.Runnable completeCallback)
      Deletes the selection in a viewer.
      static java.lang.StringdoInsert​(java.lang.String description, PropCnr target, int index, GProp<?>[] props, IPropUndoRedo undoRedo, boolean doAutoRename)
      Adds or inserts properties with undo/redo support.
      static voiddoLink​(org.eclipse.swt.widgets.Shell shell, DesignerProp base, org.eclipse.jface.viewers.ISelection selection)
      Performs a Link of properties command.
      static java.lang.StringdoMove​(boolean doPerform, java.lang.String description, PropCnr target, GProp<?> reference, boolean isAfter, GProp<?>[] props, boolean doAutoRename, IPropUndoRedo undoRedo)
      Performs the move operation of the properties, with auto-renaming as a potential dialog box.
      static voiddoMove​(DesignerProp base, org.eclipse.jface.viewers.ISelection selection, IPropUndoRedo undoRedo)
      Performs a Move of properties command by displaying a dialog box to the user so a target can be selected for the move.
      static booleandoOpen​(boolean doPerform, GProp<?>[] props)
      Performs a Open of properties command.
      static FilePropCnrdoOpen​(boolean doPerform, GProp<?> gp, PropEditorPart[] partReturn)
      Opens the Editor associated with the specified property.
      static org.eclipse.ui.IEditorPartdoOpen​(org.eclipse.core.resources.IFile file)
      Opens the Editor of the specified file.
      static booleandoOpenAndFocus​(boolean doPerform, GProp<?> gp, int index)
      Opens the selected property in its associated editor, focuses the editor and selects the appropriate property.
      static java.lang.StringdoPaste​(DesignerProp target, int position, IPropUndoRedo undoRedo)
      Performs a Paste operation with undo support.
      static java.lang.StringdoPaste​(org.eclipse.jface.viewers.ISelection selection, int position, IPropUndoRedo undoRedo)
      Performs a Paste operation with undo support.
      static java.lang.StringdoPasteLink​(DesignerProp target, IPropUndoRedo undoRedo)
      Performs a Paste-Link operation with undo support.
      static java.lang.StringdoPasteLink​(org.eclipse.jface.viewers.ISelection selection, IPropUndoRedo undoRedo)
      Performs a Paste-Link operation with undo support.
      static booleandoRename​(GProp<?> prop, Atom newName, IPropUndoRedo undoRedo)
      Performs a rename property with undo/redo support.
      static java.lang.StringdoRename​(org.eclipse.jface.viewers.ISelection selection, IPropUndoRedo undoRedo)
      Renames the selection in a viewer.
      static voiddoRename​(org.eclipse.swt.widgets.Shell shell, org.eclipse.core.resources.IResource resource, java.lang.String newName, org.eclipse.core.commands.operations.IUndoContext undoContext)
      Performs a resource rename with undo support.
      static voiddoVerify​(PropCnr property)
      Verifies the property.
      static voiddoVerify​(PropCnr property, IKStringInfoProvider kstringInfoProvider)
      Verifies the property.
      static java.lang.StringexecuteOperation​(org.eclipse.swt.widgets.Shell shell, org.eclipse.core.commands.operations.AbstractOperation op)
      Executes an operation.
      static voidexpandAll​(org.eclipse.jface.viewers.TreeViewer viewer)
      Expands all items in a "standard tree viewer" that belong to the iizi Module, i.e.
      static voidexpandAllInPath​(org.eclipse.jface.viewers.StructuredViewer viewer, org.eclipse.jface.viewers.TreePath path)
      Expands all elements in a path.
      static voidexpandAllInPaths​(org.eclipse.jface.viewers.StructuredViewer viewer, org.eclipse.jface.viewers.TreePath[] paths)
      Expands all elements in specified paths.
      static voidexpandModuleItems​(org.eclipse.jface.viewers.TreeViewer viewer)
      Expand a "standard tree viewer" with all project item of the iizi Module so that all its files are displayed.
      static PropCnrgetAncestor​(GProp<?> gp1, GProp<?> gp2)
      Gets the common ancestor of two properties.
      static PropCnrgetCommonParent​(GProp<?>[] props)
      Gets the common parent for all properties.
      static DesignerPropgetDesignerProp​(GProp<?> gp)
      Gets a DesignerProp for a property, by searching it and its parents.
      static java.util.ArrayList<DesignerProp>getDesignerProps​(GProp<?>[] props)
      Gets the DesignerProps for the specified properties.
      static ModuleFoldergetFolder​(GProp<?>[] props)
      Gets the common ModuleFolder for properties.
      static ModuleModelgetModuleModel​(GProp<?> gp)
      Gets the iizi Module Model from a property.
      static ModuleModelgetModuleModel​(GProp<?>... props)
      Gets the common Module Model from properties.
      static org.eclipse.jface.viewers.TreePathgetNearestSelectionPath​(org.eclipse.jface.viewers.StructuredViewer viewer, DesignerProp dp)
      Finds the selection path for a DesignerProp in a viewer.
      static GProp<?>[]getProps​(org.eclipse.jface.viewers.ISelection selection, java.lang.Class<?>... propClasses)
      Gets the selected properties array.
      static java.lang.ObjectgetPropsValue​(PropCnr[] containers, Atom atom)
      Helper method to get a single value from many containers.
      static org.eclipse.jface.viewers.TreePathgetSelectionPath​(org.eclipse.jface.viewers.StructuredViewer viewer, DesignerProp dp)
      Finds the selection path for a DesignerProp in a viewer.
      static org.eclipse.jface.viewers.TreePathgetSelectionPath​(org.eclipse.jface.viewers.StructuredViewer viewer, DesignerProp dp, java.util.HashSet<java.lang.Object> filtered)
      Finds the selection path for a DesignerProp in a viewer.
      static org.eclipse.jface.viewers.TreePathgetSelectionPath​(org.eclipse.jface.viewers.TreeViewer viewer, java.lang.Object element)
      Finds the selection path for a DesignerProp in a viewer.
      static org.eclipse.core.commands.operations.IUndoContextgetUndoContext​(GProp<?> gp)
      Gets the undo context for a property.
      static Atom[]getUniqueNames​(PropCnr cnr, GProp<?>[] props, java.lang.String suffix, boolean isCopy)
      Gets the names of properties to move to or add in a container.
      static booleanqueueVerify​(PropCnr property)
      Asynchronous-verifies the property in a queue in the SWT thread.
      static booleanqueueVerify​(PropCnr property, IKStringInfoProvider kstringInfoProvider, java.lang.Runnable callback)
      Asynchronous-verifies the property in a queue in the SWT thread.
      static booleanqueueVerify​(PropCnr property, java.lang.Runnable callback)
      Asynchronous-verifies the property in a queue in the SWT thread.
      static voidrestoreState​(org.eclipse.jface.viewers.Viewer viewer, ModuleRootPropCnr root, org.eclipse.ui.IMemento memento)
      Restores the state of a viewer once the viewer contents has been set.
      static voidrestoreTree​(org.eclipse.core.resources.IFile file, org.eclipse.ui.IMemento memento, java.lang.String key, org.eclipse.jface.viewers.TreeViewer viewer, PropCnr editedProperty)
      Restores the selection of the properties in the memento or the file, in the memento as a priority over the file.
      static voidsaveState​(org.eclipse.jface.viewers.Viewer viewer, org.eclipse.ui.IMemento memento)
      Saves the memento for a Tree or Table Viewer, i.e.
      static voidsaveViewer​(org.eclipse.core.resources.IFile file, org.eclipse.jface.viewers.TreeViewer viewer)
      Saves the selection and expanded states of the properties in the file permanent properties.
      static voidsaveViewer​(org.eclipse.jface.viewers.TreeViewer viewer, java.lang.StringBuilder selection, java.lang.StringBuilder expanded)
      Saves the selection and expanded state of a viewer into two buffers.
      static voidsaveViewer​(org.eclipse.ui.IMemento memento, java.lang.String key, org.eclipse.jface.viewers.TreeViewer viewer)
      Saves the selection and expanded states of the properties in the memento.
      static voidscheduleDeleteJob​(java.lang.String jobName, org.eclipse.swt.widgets.Shell shell, org.eclipse.core.resources.IResource[] resourcesToDelete, boolean deleteContent, org.eclipse.core.commands.operations.IUndoContext undoContext, java.lang.Runnable completeCallback)
      Schedules a delete resources job.
      static voidselectPropsAndFocusTreeViewer​(GProp<?>[] props, org.eclipse.jface.viewers.StructuredViewer viewer)
      Request a selection of the properties.
      static java.lang.StringsetAttribute​(GProp<?> prop, int attr, boolean flag, IPropUndoRedo undoRedo)
      Sets property attribute.
      static java.lang.StringsetError​(GProp<?> prop, java.lang.String errorID, IPropErrorItem item, IPropUndoRedo undoRedo)
      Sets property error: adds, changes or removes the error, with undo/redo support.
      static booleansetNearestSelection​(org.eclipse.jface.viewers.StructuredViewer viewer, DesignerProp dp)
      Sets the nearest selection to the DesignerProp.
      static booleansetSelection​(org.eclipse.jface.viewers.StructuredViewer viewer, DesignerProp dp)
      Sets the selection of the property.
      static intsetSelection​(org.eclipse.jface.viewers.StructuredViewer viewer, java.util.Collection<DesignerProp> list)
      Sets the selection of the properties.
      static java.lang.StringsetValue​(java.lang.String description, GProp<?>[] props, java.lang.Object[] values, IPropUndoRedo undoRedo)
      Sets property values.
      static java.lang.StringsetValue​(java.lang.String description, GProp<?> prop, java.lang.Object value, IPropUndoRedo undoRedo)
      Sets a single property value.
      static java.lang.StringsetValue​(java.lang.String description, PropCnr container, GProp<?> prop, IPropUndoRedo undoRedo)
      Sets a single property value in a property container.
      static voidsyncExec​(GEvent e, EventListener listener)
      Helper routine to execute a property event in the SWT thread synchronously.
      static java.lang.StringvalidateReferenceNameFormat​(java.lang.String name, boolean doCheckValidProject, boolean doLookup, java.lang.Class<?>[] possibleClasses)
      Validates a reference name to be of correct format.
      static org.eclipse.jface.viewers.StructuredViewerviewerContainingAllProperties​(java.lang.Object viewer, GProp<?> single, GProp<?>[] props)
      Checks if a viewer container the properties in question.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MANY_VALUES

        public static final java.lang.Object MANY_VALUES
        Special object returned for getCommonValue() when many different values exist.
    • Constructor Detail

      • PropHelper

        public PropHelper()
    • Method Detail

      • getProps

        public static GProp<?>[] getProps​(org.eclipse.jface.viewers.ISelection selection,
                                          java.lang.Class<?>... propClasses)
        Gets the selected properties array. If the selection doesn't contain any properties of the list of possible classes (i.e. has an unknown class), a null array is returned.
        Parameters:
        selection - The selection.
        propClasses - List of classes that are accepted in the returned array.
        Returns:
        The array list of selected properties, or null if the selection contains other elements than properties.
      • doCopy

        public static void doCopy​(org.eclipse.swt.widgets.Shell parent,
                                  org.eclipse.jface.viewers.ISelection selection,
                                  java.lang.Runnable completeCallback)
        Performs the Copy operation. If the selection doesn't contain properties a message box is displayed.
        Parameters:
        parent - The shell.
        selection - The selection in the viewer.
        completeCallback - If non-null, the callback that will be called in the SWT thread when undo completed (e.g. to update states).
      • doPaste

        public static java.lang.String doPaste​(org.eclipse.jface.viewers.ISelection selection,
                                               int position,
                                               IPropUndoRedo undoRedo)
        Performs a Paste operation with undo support.
        Parameters:
        selection - The selection in the viewer.
        position - The position in the target (0=inside, -1=before target in parent, 1=after target in parent).
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • doPaste

        public static java.lang.String doPaste​(DesignerProp target,
                                               int position,
                                               IPropUndoRedo undoRedo)
        Performs a Paste operation with undo support.
        Parameters:
        target - Target property.
        position - The position in the target (0=inside, -1=before target in parent, 1=after target in parent).
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • doPasteLink

        public static java.lang.String doPasteLink​(org.eclipse.jface.viewers.ISelection selection,
                                                   IPropUndoRedo undoRedo)
        Performs a Paste-Link operation with undo support.
        Parameters:
        selection - The selection in the viewer.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • doPasteLink

        public static java.lang.String doPasteLink​(DesignerProp target,
                                                   IPropUndoRedo undoRedo)
        Performs a Paste-Link operation with undo support.
        Parameters:
        target - Target property.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • doAdd

        public static java.lang.String doAdd​(java.lang.String description,
                                             PropCnr target,
                                             GProp<?> prop,
                                             IPropUndoRedo undoRedo,
                                             boolean doAutoRename)
        Adds a property with undo/redo support.
        Parameters:
        description - The description of the operation (if props.length>1, make it in plural).
        target - The target property container.
        prop - The property to add.
        undoRedo - The undo/redo interface.
        doAutoRename - Flag set to true to indicate automatic rename of existing property names.
        Returns:
        The success response is null, otherwise an error message.
      • doAdd

        public static java.lang.String doAdd​(java.lang.String description,
                                             PropCnr target,
                                             GProp<?>[] props,
                                             IPropUndoRedo undoRedo,
                                             boolean doAutoRename)
        Adds properties with undo/redo support.
        Parameters:
        description - The description of the operation (if props.length>1, make it in plural).
        target - The target property container.
        props - The properties.
        undoRedo - The undo/redo interface.
        doAutoRename - Flag set to true to indicate automatic rename of existing property names.
        Returns:
        The success response is null, otherwise an error message.
      • doInsert

        public static java.lang.String doInsert​(java.lang.String description,
                                                PropCnr target,
                                                int index,
                                                GProp<?>[] props,
                                                IPropUndoRedo undoRedo,
                                                boolean doAutoRename)
        Adds or inserts properties with undo/redo support.
        Parameters:
        description - The description of the operation (if props.length>1, make it in plural).
        target - The target property container.
        index - The index in target, -1 for none (then position is assumed to be 0, and vice versa).
        props - The properties.
        undoRedo - The undo/redo interface.
        doAutoRename - Flag set to true to indicate automatic rename of existing property names.
        Returns:
        The success response is null, otherwise an error message.
      • executeOperation

        public static java.lang.String executeOperation​(org.eclipse.swt.widgets.Shell shell,
                                                        org.eclipse.core.commands.operations.AbstractOperation op)
        Executes an operation.
        Parameters:
        shell - The shell.
        op - The operation.
        Returns:
        null For OK, otherwise an error message that has been displayed in a message box.
      • doDelete

        public static java.lang.String doDelete​(org.eclipse.jface.viewers.ISelection selection,
                                                IPropUndoRedo undoRedo,
                                                java.lang.Runnable completeCallback)
        Deletes the selection in a viewer. If the selection contains a resource, all the selected items must be resources.
        Parameters:
        selection - The selection in the viewer.
        undoRedo - The undo/redo interface.
        completeCallback - If non-null, the callback that will be called in the SWT thread when undo completed (e.g. to update states).
        Returns:
        The success response is null, otherwise an error message.
      • doCut

        public static java.lang.String doCut​(org.eclipse.jface.viewers.ISelection selection,
                                             IPropUndoRedo undoRedo,
                                             java.lang.Runnable completeCallback)
        Cuts the selection in a viewer. If the selection contains a resource, all the selected items must be resources.
        Parameters:
        selection - The selection in the viewer.
        undoRedo - The undo/redo interface.
        completeCallback - If non-null, the callback that will be called in the SWT thread when undo completed (e.g. to update states).
        Returns:
        The success response is null, otherwise an error message.
      • scheduleDeleteJob

        public static void scheduleDeleteJob​(java.lang.String jobName,
                                             org.eclipse.swt.widgets.Shell shell,
                                             org.eclipse.core.resources.IResource[] resourcesToDelete,
                                             boolean deleteContent,
                                             org.eclipse.core.commands.operations.IUndoContext undoContext,
                                             java.lang.Runnable completeCallback)
        Schedules a delete resources job.
      • doDelete

        public static java.lang.String doDelete​(java.lang.String description,
                                                GProp<?>[] props,
                                                IPropUndoRedo undoRedo,
                                                java.lang.Runnable completeCallback)
        Performs a delete of pure properties (cannot be resource based). If a property is resource based, an assertion is thrown.
        Parameters:
        description - The description of the operation.
        props - The properties to remove.
        undoRedo - The undo/redo instance.
        completeCallback - Callback called when operation completes, null for none.
        Returns:
        The success response is null, otherwise an error message.
      • doRename

        public static java.lang.String doRename​(org.eclipse.jface.viewers.ISelection selection,
                                                IPropUndoRedo undoRedo)
        Renames the selection in a viewer. The selection must be a single resource based property.
        Parameters:
        selection - The selection in the viewer.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • setValue

        public static java.lang.String setValue​(java.lang.String description,
                                                GProp<?> prop,
                                                java.lang.Object value,
                                                IPropUndoRedo undoRedo)
        Sets a single property value.
        Parameters:
        description - The description of the operation.
        prop - The property.
        value - The value.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • setValue

        public static java.lang.String setValue​(java.lang.String description,
                                                PropCnr container,
                                                GProp<?> prop,
                                                IPropUndoRedo undoRedo)
                                         throws PropException
        Sets a single property value in a property container. If the container contains the property, that property is set. If not, the property is added to the container with the set value.
        Parameters:
        description - The description of the operation.
        container - The container.
        prop - The property.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
        Throws:
        PropException - If the value cannot be set in the property.
      • setAttribute

        public static java.lang.String setAttribute​(GProp<?> prop,
                                                    int attr,
                                                    boolean flag,
                                                    IPropUndoRedo undoRedo)
        Sets property attribute.
        Parameters:
        prop - The property.
        attr - The attribute PropAttrEvent.PROP_*
        flag - The flag.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • setError

        public static java.lang.String setError​(GProp<?> prop,
                                                java.lang.String errorID,
                                                IPropErrorItem item,
                                                IPropUndoRedo undoRedo)
        Sets property error: adds, changes or removes the error, with undo/redo support.
        Parameters:
        prop - The property.
        errorID - The error ID (might be null).
        item - Error item, null to remove the error, otherwise an error instance to set the error.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • setValue

        public static java.lang.String setValue​(java.lang.String description,
                                                GProp<?>[] props,
                                                java.lang.Object[] values,
                                                IPropUndoRedo undoRedo)
        Sets property values. The arrays must be of equal lengths.
        Parameters:
        description - The description of the operation.
        props - The array of properties.
        values - The array of values.
        undoRedo - The undo/redo interface.
        Returns:
        The success response is null, otherwise an error message.
      • saveState

        public static void saveState​(org.eclipse.jface.viewers.Viewer viewer,
                                     org.eclipse.ui.IMemento memento)
        Saves the memento for a Tree or Table Viewer, i.e. the current selection and the expanded items (tree only).
        Parameters:
        viewer - The viewer.
        memento - The memento should be a child of the Editor Part saving the state.
      • restoreState

        public static void restoreState​(org.eclipse.jface.viewers.Viewer viewer,
                                        ModuleRootPropCnr root,
                                        org.eclipse.ui.IMemento memento)
        Restores the state of a viewer once the viewer contents has been set.
        Parameters:
        viewer - The viewer.
        root - The Module root property of the project.
        memento - The memento should be a child of the Editor Part saving the state, can be null.
      • getDesignerProps

        public static java.util.ArrayList<DesignerProp> getDesignerProps​(GProp<?>[] props)
        Gets the DesignerProps for the specified properties.
      • selectPropsAndFocusTreeViewer

        public static void selectPropsAndFocusTreeViewer​(GProp<?>[] props,
                                                         org.eclipse.jface.viewers.StructuredViewer viewer)
        Request a selection of the properties. This method may be called from a non-SWT thread, resulting in a synchronous operation call to the SWT thread.
      • setSelection

        public static boolean setSelection​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                           DesignerProp dp)
        Sets the selection of the property. Must be from SWT thread and focus is not changed.
        Returns:
        true if selection was set, false for failure.
      • setSelection

        public static int setSelection​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                       java.util.Collection<DesignerProp> list)
        Sets the selection of the properties. Must be from SWT thread and focus is not changed.
        Returns:
        Count of items selected, zero means failure if list is non-empty.
      • expandAllInPath

        public static void expandAllInPath​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                           org.eclipse.jface.viewers.TreePath path)
        Expands all elements in a path.
        Parameters:
        viewer - The viewer, hopefully a tree viewer.
        path - The path.
      • expandAllInPaths

        public static void expandAllInPaths​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                            org.eclipse.jface.viewers.TreePath[] paths)
        Expands all elements in specified paths.
        Parameters:
        viewer - The viewer, hopefully a tree viewer.
        paths - The paths.
      • getSelectionPath

        public static org.eclipse.jface.viewers.TreePath getSelectionPath​(org.eclipse.jface.viewers.TreeViewer viewer,
                                                                          java.lang.Object element)
        Finds the selection path for a DesignerProp in a viewer.
      • getSelectionPath

        public static org.eclipse.jface.viewers.TreePath getSelectionPath​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                                                          DesignerProp dp)
        Finds the selection path for a DesignerProp in a viewer.
      • setNearestSelection

        public static boolean setNearestSelection​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                                  DesignerProp dp)
        Sets the nearest selection to the DesignerProp.
        Returns:
        true if selection is found, false otherwise.
      • getNearestSelectionPath

        public static org.eclipse.jface.viewers.TreePath getNearestSelectionPath​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                                                                 DesignerProp dp)
        Finds the selection path for a DesignerProp in a viewer.
      • getSelectionPath

        public static org.eclipse.jface.viewers.TreePath getSelectionPath​(org.eclipse.jface.viewers.StructuredViewer viewer,
                                                                          DesignerProp dp,
                                                                          java.util.HashSet<java.lang.Object> filtered)
        Finds the selection path for a DesignerProp in a viewer.
      • doRename

        public static boolean doRename​(GProp<?> prop,
                                       Atom newName,
                                       IPropUndoRedo undoRedo)
                                throws PropTypeException
        Performs a rename property with undo/redo support.
        Returns:
        true for change, false for no change.
        Throws:
        PropTypeException - When the property cannot be renamed, same name or read-only.
      • doRename

        public static void doRename​(org.eclipse.swt.widgets.Shell shell,
                                    org.eclipse.core.resources.IResource resource,
                                    java.lang.String newName,
                                    org.eclipse.core.commands.operations.IUndoContext undoContext)
        Performs a resource rename with undo support.
      • syncExec

        public static void syncExec​(GEvent e,
                                    EventListener listener)
        Helper routine to execute a property event in the SWT thread synchronously. If the current thread is the SWT thread, the listener is called directly.
      • autoRename

        public static java.lang.String[] autoRename​(PropCnr target,
                                                    GProp<?>[] props,
                                                    java.lang.String first,
                                                    java.lang.String next,
                                                    java.lang.String next2)
        Auto-renames properties. If the source is from an assets directory and target is not, the file extension is removed if it matches the destination.
        Parameters:
        target - The target container.
        props - The properties.
        first - The first appended string, e.g. "Copy of ".
        next - The next appended string, e.g. "Copy ". The next and next2 are used to append string, e.g. "Copy 2 of NNN".
        next2 - The next #2 appended string, e.g. " of ".
        Returns:
        The string array of the property names.
      • getUndoContext

        public static org.eclipse.core.commands.operations.IUndoContext getUndoContext​(GProp<?> gp)
        Gets the undo context for a property.
        Parameters:
        gp - The property.
        Returns:
        The undo context or null for none.
      • addUndoContext

        public static void addUndoContext​(GProp<?> gp,
                                          org.eclipse.core.commands.operations.IUndoableOperation operation)
        Adds the undo contexts from a property to an operation.
      • addUndoContexts

        public static void addUndoContexts​(GProp<?>[] props,
                                           org.eclipse.core.commands.operations.IUndoableOperation operation)
        Adds the undo contexts from a property to an operation.
      • getFolder

        public static ModuleFolder getFolder​(GProp<?>[] props)
        Gets the common ModuleFolder for properties.
        Returns:
        The common Module Folder, or null for none.
      • getDesignerProp

        public static DesignerProp getDesignerProp​(GProp<?> gp)
        Gets a DesignerProp for a property, by searching it and its parents.
      • getCommonParent

        public static PropCnr getCommonParent​(GProp<?>[] props)
        Gets the common parent for all properties.
        Parameters:
        props - The properties.
        Returns:
        The common parent, or null if not possible (e.g. different projects).
      • getAncestor

        public static PropCnr getAncestor​(GProp<?> gp1,
                                          GProp<?> gp2)
        Gets the common ancestor of two properties.
      • doMove

        public static void doMove​(DesignerProp base,
                                  org.eclipse.jface.viewers.ISelection selection,
                                  IPropUndoRedo undoRedo)
        Performs a Move of properties command by displaying a dialog box to the user so a target can be selected for the move.
      • doMove

        public static java.lang.String doMove​(boolean doPerform,
                                              java.lang.String description,
                                              PropCnr target,
                                              GProp<?> reference,
                                              boolean isAfter,
                                              GProp<?>[] props,
                                              boolean doAutoRename,
                                              IPropUndoRedo undoRedo)
        Performs the move operation of the properties, with auto-renaming as a potential dialog box.
        Parameters:
        doPerform - Flag to perform the operation if true, false to test operation only.
        description - Description of the operation.
        target - Target property.
        reference - Reference property in target where to place the moved properties (can be null if target is not index based or if they should be added last).
        isAfter - Flag indicating how to move the properties in regards to the reference property (when reference is not null).
        props - Properties to move.
        doAutoRename - Auto-rename of properties.
        undoRedo - Undo-redo instance.
        Returns:
        An error message for operation, or null for success.
      • doLink

        public static void doLink​(org.eclipse.swt.widgets.Shell shell,
                                  DesignerProp base,
                                  org.eclipse.jface.viewers.ISelection selection)
        Performs a Link of properties command.
      • doOpen

        public static boolean doOpen​(boolean doPerform,
                                     GProp<?>[] props)
        Performs a Open of properties command. If a property is open in an editor, that editor is placed in focus.
        Parameters:
        doPerform - Set to false to see if this open command would succeed, true to perform the open.
        props - The properties to open in an Editor.
        Returns:
        The success flag, false if none could be opened.
      • doOpen

        public static FilePropCnr doOpen​(boolean doPerform,
                                         GProp<?> gp,
                                         PropEditorPart[] partReturn)
        Opens the Editor associated with the specified property.
        Parameters:
        doPerform - Set to false to see if this open command would succeed, true to perform the open.
        gp - The property to open in an Editor.
        partReturn - Array of 1 in length (minimum), where index 0 is filled upon successful return, or set to null for failure or no need to call doOpen on the part with the property. Set partReturn to null for no return value.
        Returns:
        The success property container opened, null if none could be opened.
      • doOpenAndFocus

        public static boolean doOpenAndFocus​(boolean doPerform,
                                             GProp<?> gp,
                                             int index)
        Opens the selected property in its associated editor, focuses the editor and selects the appropriate property.
        Parameters:
        doPerform - Flag for testing only, or to perform the actual open.
        gp - The property.
        index - Index for a multi-prop, otherwise not used.
        Returns:
        The success property container opened, null if none could be opened.
      • doOpen

        public static org.eclipse.ui.IEditorPart doOpen​(org.eclipse.core.resources.IFile file)
        Opens the Editor of the specified file.
        Parameters:
        file - The file to open.
        Returns:
        The IEditorPart, if an "iizi Module Editor", an instance of PropEditorPart. For errors, null is returned.
      • canPerform

        public static java.lang.String canPerform​(GProp<?>[] props,
                                                  int operation)
        Checks properties for a valid operation.
        Parameters:
        props - The properties.
        operation - The operation: DesignerProp.OP_MOVE or OP_DELETE.
        Returns:
        null for success (operation can be performed), otherwise the error message.
      • canPerform

        public static java.lang.String canPerform​(java.util.ArrayList<DesignerProp> list,
                                                  int operation)
        Checks properties for a valid operation.
        Parameters:
        list - The properties.
        operation - The operation (DesignerProp.OP_*).
      • expandModuleItems

        public static void expandModuleItems​(org.eclipse.jface.viewers.TreeViewer viewer)
        Expand a "standard tree viewer" with all project item of the iizi Module so that all its files are displayed.
      • expandAll

        public static void expandAll​(org.eclipse.jface.viewers.TreeViewer viewer)
        Expands all items in a "standard tree viewer" that belong to the iizi Module, i.e. doesn't expand the JRE items that takes forever...
      • validateReferenceNameFormat

        public static java.lang.String validateReferenceNameFormat​(java.lang.String name,
                                                                   boolean doCheckValidProject,
                                                                   boolean doLookup,
                                                                   java.lang.Class<?>[] possibleClasses)
        Validates a reference name to be of correct format.
        Parameters:
        name - The reference name to check.
        doCheckValidProject - To check the validity of project.
        doLookup - To look-up for real existing reference.
        possibleClasses - The classes to look-up.
        Returns:
        The error string.
      • doVerify

        public static void doVerify​(PropCnr property)
        Verifies the property. This method can only be called for editable properties that are located in a FilePropCnr or a FolderPropCnr, i.e. the data container property. All other properties will generate a logged message and no verification will take place.
        Parameters:
        property - Property to verify.
      • doVerify

        public static void doVerify​(PropCnr property,
                                    IKStringInfoProvider kstringInfoProvider)
        Verifies the property. This method can only be called for editable properties that are located in a FilePropCnr or a FolderPropCnr, i.e. the data container property. All other properties will generate a logged message and no verification will take place.
        Parameters:
        property - Property to verify.
        kstringInfoProvider - The KStringInfoProvider instance.
        Throws:
        java.lang.NullPointerException - If kstringInfoProvider is null.
      • queueVerify

        public static boolean queueVerify​(PropCnr property)
        Asynchronous-verifies the property in a queue in the SWT thread. This call can be made several times, and the property will only be verified once.

        This method can only be called for editable properties that are located in a FilePropCnr or a FolderPropCnr, i.e. the data container property. All other properties will generate a logged message and no verification will take place.

        Parameters:
        property - Property to verify.
        Returns:
        true if queued, false if already in queue for verification
      • queueVerify

        public static boolean queueVerify​(PropCnr property,
                                          java.lang.Runnable callback)
        Asynchronous-verifies the property in a queue in the SWT thread. This call can be made several times, and the property will only be verified once.

        This method can only be called for editable properties that are located in a FilePropCnr or a FolderPropCnr, i.e. the data container property. All other properties will generate a logged message and no verification will take place.

        If there is an existing entry for the property in the queue, nothing will be done and false is returned. Be careful about this as the queued item may have a different callback set! Use doVerify() if this is important!

        Parameters:
        property - Property to verify.
        callback - Callback to be called when verification has been run, null for none.
        Returns:
        true if queued, false if already in queue for verification
      • queueVerify

        public static boolean queueVerify​(PropCnr property,
                                          IKStringInfoProvider kstringInfoProvider,
                                          java.lang.Runnable callback)
        Asynchronous-verifies the property in a queue in the SWT thread. This call can be made several times, and the property will only be verified once.

        This method can only be called for editable properties that are located in a FilePropCnr or a FolderPropCnr, i.e. the data container property. All other properties will generate a logged message and no verification will take place.

        If there is an existing entry for the property in the queue, nothing will be done and false is returned. Be careful about this as the queued item may have a different callback set! Use doVerify() if this is important!

        Parameters:
        property - Property to verify.
        kstringInfoProvider - The KStringInfoProvider instance.
        callback - Callback to be called when verification has been run, null for none.
        Throws:
        java.lang.NullPointerException - If kstringInfoProvider is null.
      • saveViewer

        public static void saveViewer​(org.eclipse.ui.IMemento memento,
                                      java.lang.String key,
                                      org.eclipse.jface.viewers.TreeViewer viewer)
        Saves the selection and expanded states of the properties in the memento.
      • saveViewer

        public static void saveViewer​(org.eclipse.core.resources.IFile file,
                                      org.eclipse.jface.viewers.TreeViewer viewer)
        Saves the selection and expanded states of the properties in the file permanent properties.
      • restoreTree

        public static void restoreTree​(org.eclipse.core.resources.IFile file,
                                       org.eclipse.ui.IMemento memento,
                                       java.lang.String key,
                                       org.eclipse.jface.viewers.TreeViewer viewer,
                                       PropCnr editedProperty)
        Restores the selection of the properties in the memento or the file, in the memento as a priority over the file.
        Parameters:
        file - The file to load properties from, or null for none.
        memento - The memento to use in priority over the file, null for none.
        key - The memento key to use.
        viewer - The tree viewer.
        editedProperty - The edited property.
      • saveViewer

        public static void saveViewer​(org.eclipse.jface.viewers.TreeViewer viewer,
                                      java.lang.StringBuilder selection,
                                      java.lang.StringBuilder expanded)
        Saves the selection and expanded state of a viewer into two buffers.
      • viewerContainingAllProperties

        public static org.eclipse.jface.viewers.StructuredViewer viewerContainingAllProperties​(java.lang.Object viewer,
                                                                                               GProp<?> single,
                                                                                               GProp<?>[] props)
        Checks if a viewer container the properties in question. This method is used in the undo/redo operations for selecting in the viewers.
      • getPropsValue

        public static java.lang.Object getPropsValue​(PropCnr[] containers,
                                                     Atom atom)
        Helper method to get a single value from many containers.
        Parameters:
        containers - The containers to look-up a value in.
        atom - The name of the property to get.
        Returns:
        MANY_VALUES if the value is not common in the containers, null for no value, otherwise the value.
      • getUniqueNames

        public static Atom[] getUniqueNames​(PropCnr cnr,
                                            GProp<?>[] props,
                                            java.lang.String suffix,
                                            boolean isCopy)
        Gets the names of properties to move to or add in a container. Support also exists if the component is already in the container, then the name is not changed.
        Parameters:
        cnr - The destination container.
        props - The properties.
        suffix - String to add when name exists, e.g. " Copy" or " Move".
      • getModuleModel

        public static ModuleModel getModuleModel​(GProp<?> gp)
        Gets the iizi Module Model from a property.
        Parameters:
        gp - The property (or null for none).
        Returns:
        The Module Model instance, or null if not found.
      • getModuleModel

        public static ModuleModel getModuleModel​(GProp<?>... props)
        Gets the common Module Model from properties.