Search in sources :

Example 11 with ObjectTool

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);
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Node(org.netxms.client.objects.Node) Intent(android.content.Intent) ActivityNotFoundException(android.content.ActivityNotFoundException) OnClickListener(android.content.DialogInterface.OnClickListener) GeoLocation(org.netxms.base.GeoLocation) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 12 with ObjectTool

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);
    }
}
Also used : AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) Node(org.netxms.client.objects.Node) AdapterView(android.widget.AdapterView) SubMenu(android.view.SubMenu) GeoLocation(org.netxms.base.GeoLocation) AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 13 with ObjectTool

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();
    }
}
Also used : ObjectToolSelectionDialog(org.netxms.ui.eclipse.serverconfig.dialogs.ObjectToolSelectionDialog) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Example 14 with ObjectTool

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();
}
Also used : Action(org.eclipse.jface.action.Action) AbstractNode(org.netxms.client.objects.AbstractNode) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ObjectContext(org.netxms.ui.eclipse.objects.ObjectContext) Interface(org.netxms.client.objects.Interface) ObjectTool(org.netxms.client.objecttools.ObjectTool) HashSet(java.util.HashSet)

Example 15 with ObjectTool

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ImageData(org.eclipse.swt.graphics.ImageData) CoreException(org.eclipse.core.runtime.CoreException) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Aggregations

ObjectTool (org.netxms.client.objecttools.ObjectTool)19 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 PartInitException (org.eclipse.ui.PartInitException)5 ObjectToolDetails (org.netxms.client.objecttools.ObjectToolDetails)3 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 GeoLocation (org.netxms.base.GeoLocation)2 Node (org.netxms.client.objects.Node)2 AlertDialog (android.app.AlertDialog)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 SubMenu (android.view.SubMenu)1 AdapterView (android.widget.AdapterView)1