use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class NodeBrowser method onContextItemSelected.
/* (non-Javadoc)
* @see android.app.Activity#onContextItemSelected(android.view.MenuItem)
*/
@SuppressWarnings("deprecation")
@Override
public boolean onContextItemSelected(MenuItem item) {
if (selectedObject == null)
return super.onContextItemSelected(item);
switch(item.getItemId()) {
case R.id.find_switch_port:
Intent fspIntent = new Intent(this, ConnectionPointBrowser.class);
fspIntent.putExtra("nodeId", (int) selectedObject.getObjectId());
startActivity(fspIntent);
break;
case R.id.view_alarms:
new SyncMissingChildsTask().execute(new Integer[] { (int) selectedObject.getObjectId() });
break;
case R.id.unmanage:
service.setObjectMgmtState(selectedObject.getObjectId(), false);
refreshList();
break;
case R.id.manage:
service.setObjectMgmtState(selectedObject.getObjectId(), true);
refreshList();
break;
case R.id.poll_status:
Intent psIntent = new Intent(this, NodePollerActivity.class);
psIntent.putExtra("nodeId", (int) selectedObject.getObjectId());
psIntent.putExtra("pollType", NodePollType.STATUS);
startActivity(psIntent);
break;
case R.id.poll_configuration:
Intent pcIntent = new Intent(this, NodePollerActivity.class);
pcIntent.putExtra("nodeId", (int) selectedObject.getObjectId());
pcIntent.putExtra("pollType", NodePollType.CONFIGURATION_NORMAL);
startActivity(pcIntent);
break;
case R.id.poll_topology:
Intent ptIntent = new Intent(this, NodePollerActivity.class);
ptIntent.putExtra("nodeId", (int) selectedObject.getObjectId());
ptIntent.putExtra("pollType", NodePollType.TOPOLOGY);
startActivity(ptIntent);
break;
case R.id.poll_interfaces:
Intent piIntent = new Intent(this, NodePollerActivity.class);
piIntent.putExtra("nodeId", (int) selectedObject.getObjectId());
piIntent.putExtra("pollType", NodePollType.INTERFACES);
startActivity(piIntent);
break;
case R.id.navigate_to:
GeoLocation gl = selectedObject.getGeolocation();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + gl.getLatitude() + "," + gl.getLongitude()));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(getApplicationContext(), "Navigation unavailable", Toast.LENGTH_LONG);
}
break;
default:
// if we didn't match static menu, check if it was some of tools
List<ObjectTool> tools = service.getTools();
if (tools != null) {
for (final ObjectTool tool : tools) {
if ((int) tool.getId() == item.getItemId()) {
if ((tool.getFlags() & ObjectTool.ASK_CONFIRMATION) != 0) {
String message = tool.getConfirmationText().replaceAll("%n", selectedObject.getObjectName()).replaceAll("%a", ((Node) selectedObject).getPrimaryIP().getHostAddress());
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle(R.string.confirm_tool_execution).setMessage(message).setCancelable(true).setPositiveButton(R.string.yes, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
service.executeObjectTool(selectedObject.getObjectId(), tool);
}
}).setNegativeButton(R.string.no, null).show();
break;
}
service.executeObjectTool(selectedObject.getObjectId(), tool);
break;
}
}
}
break;
}
return super.onContextItemSelected(item);
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class NodeBrowser method onCreateContextMenu.
/* (non-Javadoc)
* @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo)
*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
android.view.MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.node_actions, menu);
AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
selectedObject = (AbstractObject) adapter.getItem(info.position);
GeoLocation gl = selectedObject.getGeolocation();
if ((gl == null) || (gl.getType() == GeoLocation.UNSET)) {
hideMenuItem(menu, R.id.navigate_to);
}
if (selectedObject instanceof Node) {
// add available tools to context menu
List<ObjectTool> tools = service.getTools();
if (tools != null) {
SubMenu subMenu = menu.addSubMenu(Menu.NONE, 0, 0, getString(R.string.menu_tools));
Iterator<ObjectTool> tl = tools.iterator();
ObjectTool tool;
while (tl.hasNext()) {
tool = tl.next();
switch(tool.getToolType()) {
case ObjectTool.TYPE_INTERNAL:
case ObjectTool.TYPE_ACTION:
case ObjectTool.TYPE_SERVER_COMMAND:
case ObjectTool.TYPE_SERVER_SCRIPT:
if (tool.isApplicableForNode((Node) selectedObject))
subMenu.add(Menu.NONE, (int) tool.getId(), 0, tool.getDisplayName());
break;
}
}
}
} else {
hideMenuItem(menu, R.id.find_switch_port);
hideMenuItem(menu, R.id.poll);
}
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class ExportFileBuilder method addObjectTools.
/**
* Add oject tools to list
*/
private void addObjectTools() {
ObjectToolSelectionDialog dlg = new ObjectToolSelectionDialog(getSite().getShell());
if (dlg.open() == Window.OK) {
for (ObjectTool t : dlg.getSelection()) tools.put(t.getId(), t);
toolsViewer.setInput(tools.values().toArray());
setModified();
}
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class Commands method onObjectChange.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.objectview.objecttabs.elements.OverviewPageElement#onObjectChange()
*/
@Override
protected void onObjectChange() {
commandBox.deleteAll(false);
if (getObject() instanceof AbstractNode) {
ObjectTool[] tools = ObjectToolsCache.getInstance().getTools();
for (final ObjectTool tool : tools) {
if (!tool.isVisibleInCommands() || !tool.isEnabled() || !tool.isApplicableForNode((AbstractNode) getObject()))
continue;
final Set<ObjectContext> nodes = new HashSet<ObjectContext>(1);
nodes.add(new ObjectContext((AbstractNode) getObject(), null));
if (!ObjectToolExecutor.isToolAllowed(tool, nodes))
continue;
final Action action = new Action(tool.getCommandDisplayName()) {
@Override
public void run() {
ObjectToolExecutor.execute(nodes, tool);
}
};
ImageDescriptor icon = ObjectToolsCache.getInstance().findIcon(tool.getId());
if (icon != null)
action.setImageDescriptor(icon);
commandBox.add(action, false);
}
} else if (getObject() instanceof Interface) {
commandBox.add(actionWakeup, false);
}
commandBox.rebuild();
}
use of org.netxms.client.objecttools.ObjectTool in project netxms by netxms.
the class ObjectToolsCache method reload.
/**
* Reload object tools from server
*/
private void reload() {
try {
List<ObjectTool> list = session.getObjectTools();
synchronized (objectTools) {
objectTools.clear();
for (ObjectTool tool : list) {
if (tool.getToolType() != ObjectTool.TYPE_LOCAL_COMMAND)
objectTools.put(tool.getId(), tool);
}
}
synchronized (icons) {
icons.clear();
for (ObjectTool tool : list) {
byte[] imageBytes = tool.getImageData();
if ((imageBytes == null) || (imageBytes.length == 0))
continue;
ByteArrayInputStream input = new ByteArrayInputStream(imageBytes);
try {
icons.put(tool.getId(), ImageDescriptor.createFromImageData(new ImageData(input)));
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError(String.format("Exception in ObjectToolsCache.reload(): toolId=%d, toolName=%s", tool.getId(), tool.getName()), e);
}
}
}
} catch (Exception e) {
// $NON-NLS-1$
Activator.logError("Exception in ObjectToolsCache.reload()", e);
}
}
Aggregations