Search in sources :

Example 6 with MobileDevice

use of org.netxms.client.objects.MobileDevice in project netxms by netxms.

the class HistoricalDataView method init.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
	 */
@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    session = (NXCSession) ConsoleSharedData.getSession();
    // Secondary ID must by in form nodeId&dciId
    // $NON-NLS-1$
    String[] parts = site.getSecondaryId().split("&");
    if (parts.length != 2)
        // $NON-NLS-1$
        throw new PartInitException("Internal error");
    nodeId = Long.parseLong(parts[0]);
    AbstractObject object = session.findObjectById(nodeId);
    if ((object == null) || (!(object instanceof AbstractNode) && !(object instanceof MobileDevice) && !(object instanceof Cluster) && !(object instanceof Sensor)))
        throw new PartInitException(Messages.get().HistoricalDataView_InvalidObjectID);
    nodeName = object.getObjectName();
    if (parts[1].contains("@")) {
        subparts = parts[1].split("@");
        try {
            dciId = Long.parseLong(subparts[0]);
            // $NON-NLS-1$
            tableName = URLDecoder.decode(subparts[1], "UTF-8");
            // $NON-NLS-1$
            instance = URLDecoder.decode(subparts[2], "UTF-8");
            // $NON-NLS-1$
            column = URLDecoder.decode(subparts[3], "UTF-8");
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    } else {
        dciId = Long.parseLong(parts[1]);
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    setPartName(nodeName + ": [" + (tableName == null ? Long.toString(dciId) : tableName) + "]");
}
Also used : MobileDevice(org.netxms.client.objects.MobileDevice) AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) Cluster(org.netxms.client.objects.Cluster) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PartInitException(org.eclipse.ui.PartInitException) Sensor(org.netxms.client.objects.Sensor)

Example 7 with MobileDevice

use of org.netxms.client.objects.MobileDevice in project netxms by netxms.

the class GeneralInfo method fillTable.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.objectview.objecttabs.elements.TableElement#fillTable()
	 */
@Override
protected void fillTable() {
    final AbstractObject object = getObject();
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    addPair(Messages.get().GeneralInfo_ID, Long.toString(object.getObjectId()));
    if (object.getGuid() != null)
        addPair(Messages.get().GeneralInfo_GUID, object.getGuid().toString());
    addPair(Messages.get().GeneralInfo_Class, object.getObjectClassName());
    if (object.isInMaintenanceMode())
        addPair(Messages.get().GeneralInfo_Status, StatusDisplayInfo.getStatusText(object.getStatus()) + Messages.get().GeneralInfo_Maintenance);
    else
        addPair(Messages.get().GeneralInfo_Status, StatusDisplayInfo.getStatusText(object.getStatus()));
    switch(object.getObjectClass()) {
        case AbstractObject.OBJECT_CHASSIS:
            Chassis chassis = (Chassis) object;
            if (chassis.getControllerId() != 0) {
                AbstractNode node = session.findObjectById(chassis.getControllerId(), AbstractNode.class);
                if (node != null) {
                    addPair(Messages.get().GeneralInfo_Controller, node.getObjectName());
                }
            }
            if (chassis.getRackId() != 0) {
                Rack rack = session.findObjectById(chassis.getRackId(), Rack.class);
                if (rack != null) {
                    addPair(Messages.get().GeneralInfo_Rack, String.format(Messages.get().GeneralInfo_Units, rack.getObjectName(), rack.isTopBottomNumbering() ? chassis.getRackPosition() : chassis.getRackPosition() - chassis.getRackHeight() + 1, rack.isTopBottomNumbering() ? chassis.getRackPosition() + chassis.getRackHeight() - 1 : chassis.getRackPosition()));
                }
            }
            break;
        case AbstractObject.OBJECT_INTERFACE:
            Interface iface = (Interface) object;
            Interface parentIface = iface.getParentInterface();
            if (parentIface != null)
                addPair("Parent interface", parentIface.getObjectName());
            addPair(Messages.get().GeneralInfo_IfIndex, Integer.toString(iface.getIfIndex()));
            String typeName = iface.getIfTypeName();
            // $NON-NLS-1$
            addPair(Messages.get().GeneralInfo_IfType, (typeName != null) ? String.format("%d (%s)", iface.getIfType(), typeName) : Integer.toString(iface.getIfType()));
            addPair(Messages.get().GeneralInfo_Description, iface.getDescription(), false);
            addPair(Messages.get().GeneralInfo_Alias, iface.getAlias(), false);
            if (iface.getMtu() > 0)
                addPair(Messages.get().GeneralInfo_MTU, Integer.toString(iface.getMtu()));
            if (iface.getSpeed() > 0)
                addPair(Messages.get().GeneralInfo_Speed, InterfaceListLabelProvider.ifSpeedTotext(iface.getSpeed()));
            addPair(Messages.get().GeneralInfo_MACAddr, iface.getMacAddress().toString());
            if ((iface.getFlags() & Interface.IF_PHYSICAL_PORT) != 0) {
                // $NON-NLS-1$
                addPair(Messages.get().GeneralInfo_SlotPort, Integer.toString(iface.getSlot()) + "/" + Integer.toString(iface.getPort()));
                AbstractNode node = iface.getParentNode();
                if ((node != null) && node.is8021xSupported()) {
                    addPair(Messages.get().GeneralInfo_8021xPAE, iface.getDot1xPaeStateAsText());
                    addPair(Messages.get().GeneralInfo_8021xBackend, iface.getDot1xBackendStateAsText());
                }
            }
            if (iface.getIpAddressList().size() > 0) {
                if (session.isZoningEnabled())
                    addPair(Messages.get().GeneralInfo_ZoneId, getZoneName(iface.getZoneId()));
                addPair(Messages.get().GeneralInfo_IPAddr, iface.getIpAddressList().get(0).toString());
                for (int i = 1; i < iface.getIpAddressList().size(); i++) // $NON-NLS-1$
                addPair("", iface.getIpAddressList().get(i).toString());
            }
            addPair(Messages.get().GeneralInfo_AdmState, iface.getAdminStateAsText());
            addPair(Messages.get().GeneralInfo_OperState, iface.getOperStateAsText());
            addPair(Messages.get().GeneralInfo_ExpectedState, ifaceExpectedState[iface.getExpectedState()]);
            break;
        case AbstractObject.OBJECT_NODE:
            AbstractNode node = (AbstractNode) object;
            if (session.isZoningEnabled())
                addPair(Messages.get().GeneralInfo_ZoneId, getZoneName(node.getZoneId()));
            addPair(Messages.get().GeneralInfo_PrimaryHostName, node.getPrimaryName());
            addPair(Messages.get().GeneralInfo_PrimaryIP, node.getPrimaryIP().getHostAddress());
            if (node.hasAgent())
                addPair(Messages.get().GeneralInfo_AgentVersion, node.getAgentVersion());
            addPair(Messages.get().GeneralInfo_SysDescr, node.getSystemDescription(), false);
            addPair(Messages.get().GeneralInfo_PlatformName, node.getPlatformName(), false);
            addPair(Messages.get().GeneralInfo_SysName, node.getSnmpSysName(), false);
            addPair(Messages.get().GeneralInfo_SysOID, node.getSnmpOID(), false);
            addPair(Messages.get().GeneralInfo_SNMPsysLocation, node.getSnmpSysLocation(), false);
            addPair(Messages.get().GeneralInfo_SNMPsysContact, node.getSnmpSysContact(), false);
            if ((node.getCapabilities() & AbstractNode.NC_IS_BRIDGE) != 0)
                addPair(Messages.get().GeneralInfo_BridgeBaseAddress, node.getBridgeBaseAddress().toString());
            addPair(Messages.get().GeneralInfo_Driver, node.getDriverName(), false);
            addPair(Messages.get().GeneralInfo_NodeType, node.getNodeType().toString(), false);
            if (node.getBootTime() != null)
                addPair(Messages.get().GeneralInfo_BootTime, RegionalSettings.getDateTimeFormat().format(node.getBootTime()), false);
            if (node.hasAgent())
                addPair(Messages.get().GeneralInfo_AgentStatus, (node.getStateFlags() & Node.NSF_AGENT_UNREACHABLE) != 0 ? Messages.get().GeneralInfo_Unreachable : Messages.get().GeneralInfo_Connected);
            if (node.getLastAgentCommTime() != null)
                addPair(Messages.get().GeneralInfo_LastAgentContact, RegionalSettings.getDateTimeFormat().format(node.getLastAgentCommTime()), false);
            if (node.getRackId() != 0) {
                Rack rack = session.findObjectById(node.getRackId(), Rack.class);
                if (rack != null) {
                    addPair(Messages.get().GeneralInfo_Rack, String.format(Messages.get().GeneralInfo_Units, rack.getObjectName(), rack.isTopBottomNumbering() ? node.getRackPosition() : node.getRackPosition() - node.getRackHeight() + 1, rack.isTopBottomNumbering() ? node.getRackPosition() + node.getRackHeight() - 1 : node.getRackPosition()));
                }
            }
            break;
        case AbstractObject.OBJECT_MOBILEDEVICE:
            MobileDevice md = (MobileDevice) object;
            if (md.getLastReportTime().getTime() == 0)
                addPair(Messages.get().GeneralInfo_LastReport, Messages.get().GeneralInfo_Never);
            else
                addPair(Messages.get().GeneralInfo_LastReport, RegionalSettings.getDateTimeFormat().format(md.getLastReportTime()));
            addPair(Messages.get().GeneralInfo_DeviceId, md.getDeviceId());
            addPair(Messages.get().GeneralInfo_Vendor, md.getVendor());
            addPair(Messages.get().GeneralInfo_Model, md.getModel());
            addPair(Messages.get().GeneralInfo_Serial, md.getSerialNumber());
            addPair(Messages.get().GeneralInfo_OS, md.getOsName());
            addPair(Messages.get().GeneralInfo_OSVersion, md.getOsVersion());
            addPair(Messages.get().GeneralInfo_User, md.getUserId(), false);
            if (md.getBatteryLevel() >= 0)
                // $NON-NLS-1$
                addPair(Messages.get().GeneralInfo_BatteryLevel, Integer.toString(md.getBatteryLevel()) + "%");
            break;
        case AbstractObject.OBJECT_SENSOR:
            Sensor sensor = (Sensor) object;
            addPair(Messages.get().SensorStatus_DeviceAddress, sensor.getDeviceAddress(), false);
            if (sensor.getMacAddress() != null && !sensor.getMacAddress().isNull())
                addPair(Messages.get().SensorStatus_MacAddress, sensor.getMacAddress().toString(), true);
            addPair(Messages.get().SensorStatus_Vendor, sensor.getVendor(), true);
            addPair(Messages.get().SensorStatus_DeviceClass, Sensor.DEV_CLASS_NAMES[sensor.getDeviceClass()]);
            addPair(Messages.get().SensorStatus_CommProtocol, Sensor.COMM_METHOD[sensor.getCommProtocol()]);
            addPair(Messages.get().SensorStatus_SerialNumber, sensor.getSerialNumber(), true);
            addPair(Messages.get().SensorStatus_MetaType, sensor.getMetaType(), true);
            addPair(Messages.get().SensorStatus_Description, sensor.getDescription(), true);
            if (sensor.getFrameCount() != 0)
                addPair(Messages.get().SensorStatus_FrameCount, Integer.toString(sensor.getFrameCount()));
            if (sensor.getSignalStrenght() != 1)
                addPair(Messages.get().SensorStatus_RSSI, Integer.toString(sensor.getSignalStrenght()));
            if (sensor.getSignalNoise() != Integer.MAX_VALUE)
                addPair(Messages.get().SensorStatus_SNR, Double.toString((double) sensor.getSignalNoise() / 10));
            if (sensor.getFrequency() != 0)
                addPair(Messages.get().SensorStatus_Frequency, Double.toString((double) sensor.getFrequency() / 10));
            break;
        case AbstractObject.OBJECT_ACCESSPOINT:
            AccessPoint ap = (AccessPoint) object;
            addPair(Messages.get().GeneralInfo_State, ap.getState().toString());
            addPair(Messages.get().GeneralInfo_Vendor, ap.getVendor());
            addPair(Messages.get().GeneralInfo_Model, ap.getModel());
            addPair(Messages.get().GeneralInfo_Serial, ap.getSerialNumber());
            addPair(Messages.get().GeneralInfo_MACAddr, ap.getMacAddress().toString());
            if (ap.getIpAddress().isValidAddress())
                addPair(Messages.get().GeneralInfo_IPAddr, ap.getIpAddress().getHostAddress());
            break;
        case AbstractObject.OBJECT_SUBNET:
            Subnet subnet = (Subnet) object;
            if (session.isZoningEnabled())
                addPair(Messages.get().GeneralInfo_ZoneId, getZoneName(subnet.getZoneId()));
            addPair(Messages.get().GeneralInfo_IPAddress, subnet.getNetworkAddress().toString());
            break;
        case AbstractObject.OBJECT_ZONE:
            Zone zone = (Zone) object;
            addPair(Messages.get().GeneralInfo_ZoneId, Long.toString(zone.getUIN()));
            break;
        case AbstractObject.OBJECT_NODELINK:
            AbstractNode linkedNode = (AbstractNode) session.findObjectById(((NodeLink) object).getNodeId(), AbstractNode.class);
            if (linkedNode != null)
                addPair(Messages.get().GeneralInfo_LinkedNode, linkedNode.getObjectName());
        case AbstractObject.OBJECT_BUSINESSSERVICE:
        case AbstractObject.OBJECT_BUSINESSSERVICEROOT:
            ServiceContainer service = (ServiceContainer) object;
            NumberFormat nf = NumberFormat.getNumberInstance();
            nf.setMinimumFractionDigits(3);
            nf.setMaximumFractionDigits(3);
            // $NON-NLS-1$
            addPair(Messages.get().GeneralInfo_UptimeDay, nf.format(service.getUptimeForDay()) + "%");
            // $NON-NLS-1$
            addPair(Messages.get().GeneralInfo_UptimeWeek, nf.format(service.getUptimeForWeek()) + "%");
            // $NON-NLS-1$
            addPair(Messages.get().GeneralInfo_UptimeMonth, nf.format(service.getUptimeForMonth()) + "%");
            break;
        case AbstractObject.OBJECT_SLMCHECK:
            ServiceCheck check = (ServiceCheck) object;
            addPair(Messages.get().GeneralInfo_IsTemplate, check.isTemplate() ? Messages.get().GeneralInfo_Yes : Messages.get().GeneralInfo_No);
            if (check.getTemplateId() != 0) {
                ServiceCheck tmpl = (ServiceCheck) session.findObjectById(check.getTemplateId(), ServiceCheck.class);
                if (tmpl != null)
                    addPair(Messages.get().GeneralInfo_Template, tmpl.getObjectName());
            }
            break;
        default:
            break;
    }
    if (object.getGeolocation().getType() != GeoLocation.UNSET)
        addPair(Messages.get().GeneralInfo_Location, object.getGeolocation().toString());
    if (!object.getPostalAddress().isEmpty())
        addPair(Messages.get().GeneralInfo_PostalAddress, object.getPostalAddress().getAddressLine());
}
Also used : Chassis(org.netxms.client.objects.Chassis) ServiceCheck(org.netxms.client.objects.ServiceCheck) NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) Zone(org.netxms.client.objects.Zone) AccessPoint(org.netxms.client.objects.AccessPoint) AccessPoint(org.netxms.client.objects.AccessPoint) Rack(org.netxms.client.objects.Rack) MobileDevice(org.netxms.client.objects.MobileDevice) ServiceContainer(org.netxms.client.objects.ServiceContainer) AbstractObject(org.netxms.client.objects.AbstractObject) NodeLink(org.netxms.client.objects.NodeLink) Subnet(org.netxms.client.objects.Subnet) Interface(org.netxms.client.objects.Interface) Sensor(org.netxms.client.objects.Sensor) NumberFormat(java.text.NumberFormat)

Example 8 with MobileDevice

use of org.netxms.client.objects.MobileDevice in project netxms by netxms.

the class TableLastValuesView method init.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
	 */
@Override
public void init(IViewSite site) throws PartInitException {
    super.init(site);
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    // Secondary ID must by in form nodeId&dciId
    // $NON-NLS-1$
    String[] parts = site.getSecondaryId().split("&");
    if (parts.length != 2)
        // $NON-NLS-1$
        throw new PartInitException("Internal error");
    objectId = Long.parseLong(parts[0]);
    AbstractObject object = session.findObjectById(objectId);
    if ((object == null) || (!(object instanceof AbstractNode) && !(object instanceof Cluster) && !(object instanceof MobileDevice) && !(object instanceof Sensor)))
        throw new PartInitException(Messages.get().TableLastValuesView_InvalidObjectID);
    dciId = Long.parseLong(parts[1]);
    // $NON-NLS-1$ //$NON-NLS-2$
    setPartName(object.getObjectName() + ": [" + Long.toString(dciId) + "]");
}
Also used : NXCSession(org.netxms.client.NXCSession) MobileDevice(org.netxms.client.objects.MobileDevice) AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) Cluster(org.netxms.client.objects.Cluster) PartInitException(org.eclipse.ui.PartInitException) Sensor(org.netxms.client.objects.Sensor)

Example 9 with MobileDevice

use of org.netxms.client.objects.MobileDevice in project netxms by netxms.

the class NXCSession method createObjectFromMessage.

/**
 * Create object from message
 *
 * @param msg Source NXCP message
 * @return NetXMS object
 */
private AbstractObject createObjectFromMessage(NXCPMessage msg) {
    final int objectClass = msg.getFieldAsInt32(NXCPCodes.VID_OBJECT_CLASS);
    AbstractObject object = createCustomObjectFromMessage(objectClass, msg);
    if (object != null)
        return object;
    switch(objectClass) {
        case AbstractObject.OBJECT_ACCESSPOINT:
            object = new AccessPoint(msg, this);
            break;
        case AbstractObject.OBJECT_AGENTPOLICY:
            object = new AgentPolicy(msg, this);
            break;
        case AbstractObject.OBJECT_AGENTPOLICY_CONFIG:
            object = new AgentPolicyConfig(msg, this);
            break;
        case AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER:
            object = new AgentPolicyLogParser(msg, this);
            break;
        case AbstractObject.OBJECT_BUSINESSSERVICE:
            object = new BusinessService(msg, this);
            break;
        case AbstractObject.OBJECT_BUSINESSSERVICEROOT:
            object = new BusinessServiceRoot(msg, this);
            break;
        case AbstractObject.OBJECT_CHASSIS:
            object = new Chassis(msg, this);
            break;
        case AbstractObject.OBJECT_CLUSTER:
            object = new Cluster(msg, this);
            break;
        case AbstractObject.OBJECT_CONDITION:
            object = new Condition(msg, this);
            break;
        case AbstractObject.OBJECT_CONTAINER:
            object = new Container(msg, this);
            break;
        case AbstractObject.OBJECT_DASHBOARDGROUP:
            object = new DashboardGroup(msg, this);
            break;
        case AbstractObject.OBJECT_DASHBOARD:
            object = new Dashboard(msg, this);
            break;
        case AbstractObject.OBJECT_DASHBOARDROOT:
            object = new DashboardRoot(msg, this);
            break;
        case AbstractObject.OBJECT_INTERFACE:
            object = new Interface(msg, this);
            break;
        case AbstractObject.OBJECT_MOBILEDEVICE:
            object = new MobileDevice(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORK:
            object = new EntireNetwork(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKMAP:
            object = new NetworkMap(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKMAPGROUP:
            object = new NetworkMapGroup(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKMAPROOT:
            object = new NetworkMapRoot(msg, this);
            break;
        case AbstractObject.OBJECT_NETWORKSERVICE:
            object = new NetworkService(msg, this);
            break;
        case AbstractObject.OBJECT_NODE:
            object = new Node(msg, this);
            break;
        case AbstractObject.OBJECT_NODELINK:
            object = new NodeLink(msg, this);
            break;
        case AbstractObject.OBJECT_POLICYGROUP:
            object = new PolicyGroup(msg, this);
            break;
        case AbstractObject.OBJECT_POLICYROOT:
            object = new PolicyRoot(msg, this);
            break;
        case AbstractObject.OBJECT_RACK:
            object = new Rack(msg, this);
            break;
        case AbstractObject.OBJECT_SENSOR:
            object = new Sensor(msg, this);
            break;
        case AbstractObject.OBJECT_SERVICEROOT:
            object = new ServiceRoot(msg, this);
            break;
        case AbstractObject.OBJECT_SLMCHECK:
            object = new ServiceCheck(msg, this);
            break;
        case AbstractObject.OBJECT_SUBNET:
            object = new Subnet(msg, this);
            break;
        case AbstractObject.OBJECT_TEMPLATE:
            object = new Template(msg, this);
            break;
        case AbstractObject.OBJECT_TEMPLATEGROUP:
            object = new TemplateGroup(msg, this);
            break;
        case AbstractObject.OBJECT_TEMPLATEROOT:
            object = new TemplateRoot(msg, this);
            break;
        case AbstractObject.OBJECT_VPNCONNECTOR:
            object = new VPNConnector(msg, this);
            break;
        case AbstractObject.OBJECT_ZONE:
            object = new Zone(msg, this);
            break;
        default:
            object = new GenericObject(msg, this);
            break;
    }
    return object;
}
Also used : Chassis(org.netxms.client.objects.Chassis) DashboardGroup(org.netxms.client.objects.DashboardGroup) ServiceCheck(org.netxms.client.objects.ServiceCheck) TemplateRoot(org.netxms.client.objects.TemplateRoot) DashboardRoot(org.netxms.client.objects.DashboardRoot) AbstractNode(org.netxms.client.objects.AbstractNode) Node(org.netxms.client.objects.Node) NetworkMapGroup(org.netxms.client.objects.NetworkMapGroup) Dashboard(org.netxms.client.objects.Dashboard) AgentPolicyConfig(org.netxms.client.objects.AgentPolicyConfig) Template(org.netxms.client.objects.Template) Rack(org.netxms.client.objects.Rack) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) Container(org.netxms.client.objects.Container) MobileDevice(org.netxms.client.objects.MobileDevice) TemplateGroup(org.netxms.client.objects.TemplateGroup) PolicyRoot(org.netxms.client.objects.PolicyRoot) Condition(org.netxms.client.objects.Condition) PolicyGroup(org.netxms.client.objects.PolicyGroup) Zone(org.netxms.client.objects.Zone) AccessPoint(org.netxms.client.objects.AccessPoint) VPNConnector(org.netxms.client.objects.VPNConnector) Cluster(org.netxms.client.objects.Cluster) NetworkMapRoot(org.netxms.client.objects.NetworkMapRoot) EntireNetwork(org.netxms.client.objects.EntireNetwork) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) ServiceRoot(org.netxms.client.objects.ServiceRoot) BusinessServiceRoot(org.netxms.client.objects.BusinessServiceRoot) BusinessService(org.netxms.client.objects.BusinessService) AgentPolicy(org.netxms.client.objects.AgentPolicy) AbstractObject(org.netxms.client.objects.AbstractObject) GenericObject(org.netxms.client.objects.GenericObject) AgentPolicyLogParser(org.netxms.client.objects.AgentPolicyLogParser) NetworkService(org.netxms.client.objects.NetworkService) NodeLink(org.netxms.client.objects.NodeLink) Subnet(org.netxms.client.objects.Subnet) Interface(org.netxms.client.objects.Interface) NetworkMap(org.netxms.client.objects.NetworkMap) Sensor(org.netxms.client.objects.Sensor)

Example 10 with MobileDevice

use of org.netxms.client.objects.MobileDevice in project netxms by netxms.

the class ObjectGeoLocationViewer method drawObjectToolTip.

/**
 * Draw tooltip for current object
 *
 * @param gc
 */
private void drawObjectToolTip(GC gc) {
    gc.setFont(objectToolTipHeaderFont);
    Point titleSize = gc.textExtent(currentObject.getObjectName());
    gc.setFont(JFaceResources.getDefaultFont());
    // Calculate width and height
    int width = Math.max(titleSize.x + 12, 128);
    int height = OBJECT_TOOLTIP_Y_MARGIN * 2 + titleSize.y + 2 + OBJECT_TOOLTIP_SPACING;
    final String location = currentObject.getGeolocation().toString();
    Point pt = gc.textExtent(location);
    if (width < pt.x)
        width = pt.x;
    height += pt.y;
    String locationDetails;
    if ((currentObject.getGeolocation().getTimestamp().getTime() > 0) && currentObject.getGeolocation().isAutomatic()) {
        locationDetails = String.format(Messages.get().ObjectGeoLocationViewer_ObtainedFrom, RegionalSettings.getDateTimeFormat().format(currentObject.getGeolocation().getTimestamp()), (currentObject.getGeolocation().getType() == GeoLocation.GPS) ? Messages.get().ObjectGeoLocationViewer_GPS : Messages.get().ObjectGeoLocationViewer_Network);
        pt = gc.textExtent(locationDetails);
        if (width < pt.x)
            width = pt.x;
        height += pt.y;
    } else {
        locationDetails = null;
    }
    final String postalAddress = currentObject.getPostalAddress().getAddressLine();
    if (!postalAddress.isEmpty()) {
        pt = gc.textExtent(postalAddress);
        if (width < pt.x)
            width = pt.x;
        height += pt.y + OBJECT_TOOLTIP_SPACING;
    }
    String lastReport, batteryLevel;
    if (currentObject instanceof MobileDevice) {
        lastReport = String.format(Messages.get().ObjectGeoLocationViewer_LastReport, ((MobileDevice) currentObject).getLastReportTime().getTime() > 0 ? RegionalSettings.getDateTimeFormat().format(((MobileDevice) currentObject).getLastReportTime()) : Messages.get().ObjectGeoLocationViewer_Never);
        pt = gc.textExtent(lastReport);
        if (width < pt.x)
            width = pt.x;
        height += pt.y + OBJECT_TOOLTIP_SPACING * 2 + 1;
        if (((MobileDevice) currentObject).getBatteryLevel() >= 0) {
            batteryLevel = String.format(Messages.get().ObjectGeoLocationViewer_BatteryLevel, ((MobileDevice) currentObject).getBatteryLevel());
            pt = gc.textExtent(batteryLevel);
            if (width < pt.x)
                width = pt.x;
            height += pt.y;
        } else {
            batteryLevel = null;
        }
    } else {
        lastReport = null;
        batteryLevel = null;
    }
    if ((currentObject.getComments() != null) && !currentObject.getComments().isEmpty()) {
        pt = gc.textExtent(currentObject.getComments());
        if (width < pt.x)
            width = pt.x;
        height += pt.y + OBJECT_TOOLTIP_SPACING * 2 + 1;
    }
    width += OBJECT_TOOLTIP_X_MARGIN * 2;
    Rectangle ca = getClientArea();
    Rectangle rect = new Rectangle(objectToolTipLocation.x - width / 2, objectToolTipLocation.y - height / 2, width, height);
    if (rect.x < 0)
        rect.x = 0;
    else if (rect.x + rect.width >= ca.width)
        rect.x = ca.width - rect.width - 1;
    if (rect.y < 0)
        rect.y = 0;
    else if (rect.y + rect.height >= ca.height)
        rect.y = ca.height - rect.height - 1;
    gc.setBackground(colorCache.create(224, 224, 224));
    gc.setAlpha(192);
    gc.fillRoundRectangle(rect.x, rect.y, rect.width, rect.height, 3, 3);
    gc.setForeground(colorCache.create(92, 92, 92));
    gc.setAlpha(255);
    gc.setLineWidth(3);
    gc.drawRoundRectangle(rect.x, rect.y, rect.width, rect.height, 3, 3);
    gc.setLineWidth(1);
    int y = rect.y + OBJECT_TOOLTIP_Y_MARGIN + titleSize.y + 2;
    gc.drawLine(rect.x + 1, y, rect.x + rect.width - 1, y);
    gc.setBackground(StatusDisplayInfo.getStatusColor(currentObject.getStatus()));
    gc.fillOval(rect.x + OBJECT_TOOLTIP_X_MARGIN, rect.y + OBJECT_TOOLTIP_Y_MARGIN + titleSize.y / 2 - 4, 8, 8);
    gc.setForeground(colorCache.create(0, 0, 0));
    gc.setFont(objectToolTipHeaderFont);
    gc.drawText(currentObject.getObjectName(), rect.x + OBJECT_TOOLTIP_X_MARGIN + 12, rect.y + OBJECT_TOOLTIP_Y_MARGIN, true);
    gc.setFont(JFaceResources.getDefaultFont());
    // $NON-NLS-1$
    int textLineHeight = gc.textExtent("M").y;
    y = rect.y + OBJECT_TOOLTIP_Y_MARGIN + titleSize.y + OBJECT_TOOLTIP_SPACING + 2;
    gc.drawText(location, rect.x + OBJECT_TOOLTIP_X_MARGIN, y, true);
    if (locationDetails != null) {
        y += textLineHeight;
        gc.drawText(locationDetails, rect.x + OBJECT_TOOLTIP_X_MARGIN, y, true);
    }
    if (!postalAddress.isEmpty()) {
        y += textLineHeight;
        gc.drawText(postalAddress, rect.x + OBJECT_TOOLTIP_X_MARGIN, y, true);
    }
    if (lastReport != null) {
        y += textLineHeight + OBJECT_TOOLTIP_SPACING;
        gc.setForeground(colorCache.create(92, 92, 92));
        gc.drawLine(rect.x + 1, y, rect.x + rect.width - 1, y);
        y += OBJECT_TOOLTIP_SPACING;
        gc.setForeground(colorCache.create(0, 0, 0));
        gc.drawText(lastReport, rect.x + OBJECT_TOOLTIP_X_MARGIN, y, true);
        if (batteryLevel != null) {
            y += textLineHeight;
            gc.drawText(batteryLevel, rect.x + OBJECT_TOOLTIP_X_MARGIN, y, true);
        }
    }
    if ((currentObject.getComments() != null) && !currentObject.getComments().isEmpty()) {
        y += textLineHeight + OBJECT_TOOLTIP_SPACING;
        gc.setForeground(colorCache.create(92, 92, 92));
        gc.drawLine(rect.x + 1, y, rect.x + rect.width - 1, y);
        y += OBJECT_TOOLTIP_SPACING;
        gc.setForeground(colorCache.create(0, 0, 0));
        gc.drawText(currentObject.getComments(), rect.x + OBJECT_TOOLTIP_X_MARGIN, y, true);
    }
    objectTooltipRectangle = rect;
}
Also used : MobileDevice(org.netxms.client.objects.MobileDevice) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Aggregations

MobileDevice (org.netxms.client.objects.MobileDevice)10 AbstractObject (org.netxms.client.objects.AbstractObject)8 Sensor (org.netxms.client.objects.Sensor)8 AbstractNode (org.netxms.client.objects.AbstractNode)7 Cluster (org.netxms.client.objects.Cluster)7 Subnet (org.netxms.client.objects.Subnet)5 Rack (org.netxms.client.objects.Rack)4 Template (org.netxms.client.objects.Template)4 PartInitException (org.eclipse.ui.PartInitException)3 Condition (org.netxms.client.objects.Condition)3 Container (org.netxms.client.objects.Container)3 Node (org.netxms.client.objects.Node)3 ServiceRoot (org.netxms.client.objects.ServiceRoot)3 Zone (org.netxms.client.objects.Zone)3 ArrayList (java.util.ArrayList)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 NXCSession (org.netxms.client.NXCSession)2 AccessPoint (org.netxms.client.objects.AccessPoint)2 AgentPolicy (org.netxms.client.objects.AgentPolicy)2 BusinessService (org.netxms.client.objects.BusinessService)2