use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class ExecObjectToolTask method doInBackground.
/* (non-Javadoc)
* @see android.os.AsyncTask#doInBackground(Params[])
*/
@Override
protected Exception doInBackground(Object... params) {
service = (ClientConnectorService) params[3];
try {
ObjectTool objectTool = (ObjectTool) params[2];
NXCSession session = (NXCSession) params[0];
Long objectId = (Long) params[1];
switch(objectTool.getToolType()) {
case ObjectTool.TYPE_INTERNAL:
if (objectTool.getData().equals("wakeup")) {
session.wakeupNode(objectId);
break;
}
case ObjectTool.TYPE_ACTION:
session.executeAction(objectId, objectTool.getData(), null);
break;
case ObjectTool.TYPE_SERVER_COMMAND:
session.executeServerCommand(objectId, objectTool.getData(), null);
break;
case ObjectTool.TYPE_SERVER_SCRIPT:
session.executeLibraryScript(objectId, objectTool.getData(), null, null);
break;
}
} catch (Exception e) {
return e;
}
return null;
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class NXCSession method getObjectTools.
/**
* Get list of configured object tools
*
* @return List of object tools
* @throws IOException if socket I/O error occurs
* @throws NXCException if NetXMS server returns an error or operation was timed out
*/
public List<ObjectTool> getObjectTools() throws IOException, NXCException {
final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_OBJECT_TOOLS);
sendMessage(msg);
final NXCPMessage response = waitForRCC(msg.getMessageId());
int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_TOOLS);
final List<ObjectTool> list = new ArrayList<ObjectTool>(count);
long varId = NXCPCodes.VID_OBJECT_TOOLS_BASE;
for (int i = 0; i < count; i++) {
list.add(new ObjectTool(response, varId));
varId += 10000;
}
return list;
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class ObjectToolsDynamicMenu method fill.
/* (non-Javadoc)
* @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
*/
@Override
public void fill(Menu menu, int index) {
Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
if ((selection == null) || !(selection instanceof IStructuredSelection))
return;
final Set<ObjectContext> nodes = buildNodeSet((IStructuredSelection) selection);
final Menu toolsMenu = new Menu(menu);
final ImageCache imageCache = new ImageCache();
toolsMenu.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
imageCache.dispose();
}
});
ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
Arrays.sort(tools, new Comparator<ObjectTool>() {
@Override
public int compare(ObjectTool arg0, ObjectTool arg1) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
return arg0.getName().replace("&", "").compareToIgnoreCase(arg1.getName().replace("&", ""));
}
});
Map<String, Menu> menus = new HashMap<String, Menu>();
int added = 0;
for (int i = 0; i < tools.length; i++) {
boolean enabled = (tools[i].getFlags() & ObjectTool.DISABLED) == 0;
if (enabled && ObjectToolExecutor.isToolAllowed(tools[i], nodes) && ObjectToolExecutor.isToolApplicable(tools[i], nodes)) {
// $NON-NLS-1$
String[] path = tools[i].getName().split("\\-\\>");
Menu rootMenu = toolsMenu;
for (int j = 0; j < path.length - 1; j++) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
final String key = rootMenu.hashCode() + "@" + path[j].replace("&", "");
Menu currMenu = menus.get(key);
if (currMenu == null) {
currMenu = new Menu(rootMenu);
MenuItem item = new MenuItem(rootMenu, SWT.CASCADE);
item.setText(path[j]);
item.setMenu(currMenu);
menus.put(key, currMenu);
}
rootMenu = currMenu;
}
final MenuItem item = new MenuItem(rootMenu, SWT.PUSH);
item.setText(path[path.length - 1]);
ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tools[i].getId());
if (icon != null)
item.setImage(imageCache.add(icon));
item.setData(tools[i]);
item.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ObjectToolExecutor.execute(nodes, (ObjectTool) item.getData());
}
});
added++;
}
}
if (added > 0) {
MenuItem toolsMenuItem = new MenuItem(menu, SWT.CASCADE, index);
toolsMenuItem.setText(Messages.get().ObjectToolsDynamicMenu_TopLevelLabel);
toolsMenuItem.setMenu(toolsMenu);
} else {
toolsMenu.dispose();
}
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class ObjectToolSelectionDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
final Composite dialogArea = (Composite) super.createDialogArea(parent);
GridLayout layout = new GridLayout();
layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
dialogArea.setLayout(layout);
viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((ObjectTool) element).getName();
}
});
viewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
return ((ObjectTool) e1).getName().compareToIgnoreCase(((ObjectTool) e2).getName());
}
});
viewer.setInput(ObjectToolsCache.getInstance().getTools());
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.heightHint = 400;
viewer.getControl().setLayoutData(gd);
return dialogArea;
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class ObjectToolsEditor method setSelectedEnabled.
private void setSelectedEnabled() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.isEmpty())
return;
if (!MessageDialogHelper.openConfirm(getSite().getShell(), Messages.get().ObjectToolsEditor_Confirmation, Messages.get().ObjectToolsEditor_AckToEnableObjTool))
return;
final Object[] objects = selection.toArray();
new ConsoleJob(Messages.get(viewer.getControl().getDisplay()).ObjectToolsEditor_EnableObjTool, this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
@Override
protected String getErrorMessage() {
return Messages.get(getDisplay()).ObjectToolsEditor_ErrorDisablingObjTools;
}
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
for (int i = 0; i < objects.length; i++) {
if ((((ObjectTool) objects[i]).getFlags() & ObjectTool.DISABLED) > 0)
session.changeObjecToolDisableStatuss(((ObjectTool) objects[i]).getId(), true);
}
}
}.start();
}
Aggregations