Search in sources :

Example 1 with ObjectActionValidator

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

the class ObjectBrowser method isValidObjectForMove.

/**
 * Check if given selection object is valid for move
 *
 * @return true if current selection object is valid for moving object
 */
public boolean isValidObjectForMove(TreeItem[] selection, int i, SubtreeType subtree) {
    if (selection[i].getParentItem() == null)
        return false;
    final AbstractObject currentObject = (AbstractObject) selection[i].getData();
    final AbstractObject parentObject = (AbstractObject) selection[i].getParentItem().getData();
    for (ObjectActionValidator v : actionValidators) {
        int result = v.isValidSelectionForMove(subtree, currentObject, parentObject);
        if (result == ObjectActionValidator.APPROVE)
            return true;
        if (result == ObjectActionValidator.REJECT)
            return false;
    }
    return false;
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) ObjectActionValidator(org.netxms.ui.eclipse.objectbrowser.api.ObjectActionValidator)

Example 2 with ObjectActionValidator

use of org.netxms.ui.eclipse.objectbrowser.api.ObjectActionValidator 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)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)2 ObjectActionValidator (org.netxms.ui.eclipse.objectbrowser.api.ObjectActionValidator)2 ArrayList (java.util.ArrayList)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)1 AgentPolicy (org.netxms.client.objects.AgentPolicy)1 BusinessService (org.netxms.client.objects.BusinessService)1 BusinessServiceRoot (org.netxms.client.objects.BusinessServiceRoot)1 Cluster (org.netxms.client.objects.Cluster)1 Condition (org.netxms.client.objects.Condition)1 Container (org.netxms.client.objects.Container)1 Dashboard (org.netxms.client.objects.Dashboard)1 DashboardGroup (org.netxms.client.objects.DashboardGroup)1 DashboardRoot (org.netxms.client.objects.DashboardRoot)1 MobileDevice (org.netxms.client.objects.MobileDevice)1 NetworkMap (org.netxms.client.objects.NetworkMap)1 NetworkMapGroup (org.netxms.client.objects.NetworkMapGroup)1 NetworkMapRoot (org.netxms.client.objects.NetworkMapRoot)1 Node (org.netxms.client.objects.Node)1