Search in sources :

Example 11 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class Location method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected boolean applyChanges(final boolean isApply) {
    int type = GeoLocation.UNSET;
    if (radioTypeManual.getSelection())
        type = GeoLocation.MANUAL;
    else if (radioTypeAuto.getSelection())
        type = GeoLocation.GPS;
    GeoLocation location;
    if (type == GeoLocation.MANUAL) {
        try {
            location = GeoLocation.parseGeoLocation(latitude.getText(), longitude.getText());
        } catch (GeoLocationFormatException e) {
            MessageDialogHelper.openError(getShell(), Messages.get().Location_Error, Messages.get().Location_FormatError);
            return false;
        }
    } else {
        location = new GeoLocation(type == GeoLocation.GPS);
    }
    final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
    md.setGeolocation(location);
    md.setPostalAddress(new PostalAddress(country.getText().trim(), city.getText().trim(), streetAddress.getText().trim(), postcode.getText().trim()));
    if (isApply)
        setValid(false);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(String.format(Messages.get().Location_JobName, object.getObjectName()), null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.modifyObject(md);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().Location_JobError;
        }

        @Override
        protected void jobFinalize() {
            if (isApply) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        Location.this.setValid(true);
                    }
                });
            }
        }
    }.start();
    return true;
}
Also used : PostalAddress(org.netxms.base.PostalAddress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException) GeoLocation(org.netxms.base.GeoLocation) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) GeoLocationFormatException(org.netxms.base.GeoLocationFormatException)

Example 12 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class DeviceReportTest method testDeviceReports.

public void testDeviceReports() throws Exception {
    final Session session = connect();
    session.reportDeviceSystemInfo("Raden Solutions", "Virtual Device", "JVM", System.getProperty("java.version"), "000000-000000-000000", null);
    session.reportDeviceStatus(null, new GeoLocation(51.5171, 0.1062), 0, 70);
    session.disconnect();
}
Also used : GeoLocation(org.netxms.base.GeoLocation)

Example 13 with GeoLocation

use of org.netxms.base.GeoLocation in project netxms by netxms.

the class NXCSession method getLocationHistory.

/**
 * Get location history for given object.
 *
 * @param objectId The object ID
 * @param from The date from
 * @param to The date to
 * @return List of location history
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<GeoLocation> getLocationHistory(long objectId, Date from, Date to) throws NXCException, IOException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_LOC_HISTORY);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) objectId);
    msg.setField(NXCPCodes.VID_TIME_FROM, from);
    msg.setField(NXCPCodes.VID_TIME_TO, to);
    sendMessage(msg);
    NXCPMessage response = waitForRCC(msg.getMessageId());
    int size = response.getFieldAsInt32(NXCPCodes.VID_NUM_RECORDS);
    List<GeoLocation> elements = new ArrayList<GeoLocation>();
    long fieldId = NXCPCodes.VID_LOC_LIST_BASE;
    for (int i = 0; i < size; i++, fieldId += 10) {
        elements.add(new GeoLocation(response, fieldId));
    }
    Collections.sort(elements, new Comparator<GeoLocation>() {

        @Override
        public int compare(GeoLocation l1, GeoLocation l2) {
            return l1.getTimestamp().compareTo(l2.getTimestamp());
        }
    });
    return elements;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) GeoLocation(org.netxms.base.GeoLocation) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 14 with GeoLocation

use of org.netxms.base.GeoLocation 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 15 with GeoLocation

use of org.netxms.base.GeoLocation 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)

Aggregations

GeoLocation (org.netxms.base.GeoLocation)26 Point (org.eclipse.swt.graphics.Point)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 GeoLocationFormatException (org.netxms.base.GeoLocationFormatException)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 NXCSession (org.netxms.client.NXCSession)3 Area (org.netxms.ui.eclipse.osm.tools.Area)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 Group (org.eclipse.swt.widgets.Group)2 NXCPMessage (org.netxms.base.NXCPMessage)2 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 Node (org.netxms.client.objects.Node)2