Search in sources :

Example 1 with SubtreeType

use of org.netxms.ui.eclipse.objectbrowser.api.SubtreeType in project netxms by netxms.

the class ObjectBrowser method registerActionValidators.

/**
 * Register object action validators
 */
private void registerActionValidators() {
    List<ActionValidatorData> list = new ArrayList<ActionValidatorData>();
    // Read all registered extensions and create validators
    final IExtensionRegistry reg = Platform.getExtensionRegistry();
    // $NON-NLS-1$
    IConfigurationElement[] elements = reg.getConfigurationElementsFor("org.netxms.ui.eclipse.objectbrowser.objectActionValidators");
    for (int i = 0; i < elements.length; i++) {
        try {
            final ActionValidatorData v = new ActionValidatorData();
            // $NON-NLS-1$
            v.validator = (ObjectActionValidator) elements[i].createExecutableExtension("class");
            // $NON-NLS-1$
            v.priority = safeParseInt(elements[i].getAttribute("priority"));
            list.add(v);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    // Sort handlers by priority
    Collections.sort(list, new Comparator<ActionValidatorData>() {

        @Override
        public int compare(ActionValidatorData arg0, ActionValidatorData arg1) {
            return arg0.priority - arg1.priority;
        }
    });
    actionValidators = new ObjectActionValidator[list.size() + 1];
    int i = 0;
    for (ActionValidatorData v : list) actionValidators[i++] = v.validator;
    // Default validator
    actionValidators[i] = new ObjectActionValidator() {

        @Override
        public int isValidSelectionForMove(SubtreeType subtree, AbstractObject currentObject, AbstractObject parentObject) {
            switch(subtree) {
                case INFRASTRUCTURE:
                    return ((currentObject instanceof Node) || (currentObject instanceof Cluster) || (currentObject instanceof Subnet) || (currentObject instanceof Condition) || (currentObject instanceof Rack) || (currentObject instanceof MobileDevice) || (currentObject instanceof Container) || (currentObject instanceof Sensor)) && ((parentObject instanceof Container) || (parentObject instanceof ServiceRoot)) ? APPROVE : REJECT;
                case TEMPLATES:
                    return ((currentObject instanceof Template) || (currentObject instanceof TemplateGroup)) && ((parentObject instanceof TemplateGroup) || (parentObject instanceof TemplateRoot)) ? APPROVE : REJECT;
                case BUSINESS_SERVICES:
                    return (currentObject instanceof BusinessService) && ((parentObject instanceof BusinessService) || (parentObject instanceof BusinessServiceRoot)) ? APPROVE : REJECT;
                case MAPS:
                    return ((currentObject instanceof NetworkMap) || (currentObject instanceof NetworkMapGroup)) && ((parentObject instanceof NetworkMapGroup) || (parentObject instanceof NetworkMapRoot)) ? APPROVE : REJECT;
                case DASHBOARDS:
                    return (((currentObject instanceof Dashboard) || (currentObject instanceof DashboardGroup)) && ((parentObject instanceof DashboardRoot) || (parentObject instanceof DashboardGroup) || (parentObject instanceof Dashboard))) ? APPROVE : REJECT;
                case POLICIES:
                    return ((currentObject instanceof AgentPolicy) || (currentObject instanceof PolicyGroup)) && ((parentObject instanceof PolicyGroup) || (parentObject instanceof PolicyRoot)) ? APPROVE : REJECT;
                default:
                    return REJECT;
            }
        }
    };
}
Also used : TemplateRoot(org.netxms.client.objects.TemplateRoot) DashboardGroup(org.netxms.client.objects.DashboardGroup) Node(org.netxms.client.objects.Node) DashboardRoot(org.netxms.client.objects.DashboardRoot) ArrayList(java.util.ArrayList) NetworkMapGroup(org.netxms.client.objects.NetworkMapGroup) Dashboard(org.netxms.client.objects.Dashboard) Template(org.netxms.client.objects.Template) SubtreeType(org.netxms.ui.eclipse.objectbrowser.api.SubtreeType) Rack(org.netxms.client.objects.Rack) Container(org.netxms.client.objects.Container) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) MobileDevice(org.netxms.client.objects.MobileDevice) TemplateGroup(org.netxms.client.objects.TemplateGroup) PolicyRoot(org.netxms.client.objects.PolicyRoot) ObjectActionValidator(org.netxms.ui.eclipse.objectbrowser.api.ObjectActionValidator) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Condition(org.netxms.client.objects.Condition) PolicyGroup(org.netxms.client.objects.PolicyGroup) Cluster(org.netxms.client.objects.Cluster) NetworkMapRoot(org.netxms.client.objects.NetworkMapRoot) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ServiceRoot(org.netxms.client.objects.ServiceRoot) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) BusinessService(org.netxms.client.objects.BusinessService) AgentPolicy(org.netxms.client.objects.AgentPolicy) CoreException(org.eclipse.core.runtime.CoreException) AbstractObject(org.netxms.client.objects.AbstractObject) Subnet(org.netxms.client.objects.Subnet) NetworkMap(org.netxms.client.objects.NetworkMap) Sensor(org.netxms.client.objects.Sensor)

Example 2 with SubtreeType

use of org.netxms.ui.eclipse.objectbrowser.api.SubtreeType in project netxms by netxms.

the class ObjectTree method enableDropSupport.

/**
 * Enable drop support in object tree
 */
public // SubtreeType infrastructure
void enableDropSupport(// SubtreeType infrastructure
final ObjectBrowser obj) {
    final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    objectTree.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(objectTree) {

        int operation = 0;

        @Override
        public boolean performDrop(Object data) {
            TreeSelection selection = (TreeSelection) data;
            List<?> movableSelection = selection.toList();
            for (int i = 0; i < movableSelection.size(); i++) {
                AbstractObject movableObject = (AbstractObject) movableSelection.get(i);
                TreePath path = selection.getPaths()[0];
                AbstractObject parent = (AbstractObject) path.getSegment(path.getSegmentCount() - 2);
                obj.performObjectMove((AbstractObject) getCurrentTarget(), parent, movableObject, operation == DND.DROP_MOVE ? true : false);
            }
            return true;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            this.operation = operation;
            if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
                return false;
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty())
                return false;
            for (final Object object : selection.toList()) {
                SubtreeType subtree = null;
                if ((object instanceof AbstractObject)) {
                    if (obj.isValidSelectionForMove(SubtreeType.INFRASTRUCTURE))
                        subtree = SubtreeType.INFRASTRUCTURE;
                    else if (obj.isValidSelectionForMove(SubtreeType.TEMPLATES))
                        subtree = SubtreeType.TEMPLATES;
                    else if (obj.isValidSelectionForMove(SubtreeType.BUSINESS_SERVICES))
                        subtree = SubtreeType.BUSINESS_SERVICES;
                    else if (obj.isValidSelectionForMove(SubtreeType.DASHBOARDS))
                        subtree = SubtreeType.DASHBOARDS;
                    else if (obj.isValidSelectionForMove(SubtreeType.MAPS))
                        subtree = SubtreeType.MAPS;
                    else if (obj.isValidSelectionForMove(SubtreeType.POLICIES))
                        subtree = SubtreeType.POLICIES;
                }
                if (subtree == null)
                    return false;
                Set<Integer> filter;
                switch(subtree) {
                    case INFRASTRUCTURE:
                        filter = ObjectSelectionDialog.createContainerSelectionFilter();
                        break;
                    case TEMPLATES:
                        filter = ObjectSelectionDialog.createTemplateGroupSelectionFilter();
                        break;
                    case BUSINESS_SERVICES:
                        filter = ObjectSelectionDialog.createBusinessServiceSelectionFilter();
                        break;
                    case DASHBOARDS:
                        if (object instanceof DashboardGroup)
                            filter = ObjectSelectionDialog.createDashboardGroupSelectionFilter();
                        else
                            filter = ObjectSelectionDialog.createDashboardSelectionFilter();
                        break;
                    case MAPS:
                        filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                        break;
                    case POLICIES:
                        filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
                        break;
                    default:
                        filter = null;
                        break;
                }
                if ((filter == null) || !filter.contains(((AbstractObject) target).getObjectClass()) || target.equals(object))
                    return false;
            }
            return true;
        }
    });
}
Also used : DashboardGroup(org.netxms.client.objects.DashboardGroup) Set(java.util.Set) HashSet(java.util.HashSet) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SubtreeType(org.netxms.ui.eclipse.objectbrowser.api.SubtreeType) TreePath(org.eclipse.jface.viewers.TreePath) TransferData(org.eclipse.swt.dnd.TransferData) TreeSelection(org.eclipse.jface.viewers.TreeSelection) AbstractObject(org.netxms.client.objects.AbstractObject) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) AbstractObject(org.netxms.client.objects.AbstractObject) List(java.util.List)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)2 DashboardGroup (org.netxms.client.objects.DashboardGroup)2 SubtreeType (org.netxms.ui.eclipse.objectbrowser.api.SubtreeType)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreePath (org.eclipse.jface.viewers.TreePath)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 ViewerDropAdapter (org.eclipse.jface.viewers.ViewerDropAdapter)1 Transfer (org.eclipse.swt.dnd.Transfer)1 TransferData (org.eclipse.swt.dnd.TransferData)1 AgentPolicy (org.netxms.client.objects.AgentPolicy)1 BusinessService (org.netxms.client.objects.BusinessService)1 BusinessServiceRoot (org.netxms.client.objects.BusinessServiceRoot)1