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;
}
}
};
}
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;
}
});
}
Aggregations