Search in sources :

Example 1 with MappingTableDescriptor

use of org.netxms.client.mt.MappingTableDescriptor in project netxms by netxms.

the class NXCSession method listMappingTables.

/**
 * Get list of all configured mapping tables.
 *
 * @return List of MappingTableDescriptor objects
 * @throws IOException if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<MappingTableDescriptor> listMappingTables() throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_LIST_MAPPING_TABLES);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_ELEMENTS);
    final List<MappingTableDescriptor> list = new ArrayList<MappingTableDescriptor>(count);
    long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
    for (int i = 0; i < count; i++) {
        list.add(new MappingTableDescriptor(response, varId));
        varId += 10;
    }
    return list;
}
Also used : MappingTableDescriptor(org.netxms.client.mt.MappingTableDescriptor) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 2 with MappingTableDescriptor

use of org.netxms.client.mt.MappingTableDescriptor in project netxms by netxms.

the class MappingTableListComparator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    int result;
    MappingTableDescriptor d1 = (MappingTableDescriptor) e1;
    MappingTableDescriptor d2 = (MappingTableDescriptor) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case MappingTables.COLUMN_ID:
            result = d1.getId() - d2.getId();
            break;
        case MappingTables.COLUMN_NAME:
            result = d1.getName().compareToIgnoreCase(d2.getName());
            break;
        case MappingTables.COLUMN_DESCRIPTION:
            result = d1.getDescription().compareToIgnoreCase(d2.getDescription());
            break;
        case MappingTables.COLUMN_FLAGS:
            result = d1.getFlags() - d2.getFlags();
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : MappingTableDescriptor(org.netxms.client.mt.MappingTableDescriptor) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 3 with MappingTableDescriptor

use of org.netxms.client.mt.MappingTableDescriptor in project netxms by netxms.

the class MappingTables method editTable.

/**
 * Edit selected table
 */
private void editTable() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if ((selection == null) || (selection.size() != 1))
        return;
    MappingTableDescriptor d = (MappingTableDescriptor) selection.getFirstElement();
    try {
        getSite().getPage().showView(MappingTableEditor.ID, Integer.toString(d.getId()), IWorkbenchPage.VIEW_ACTIVATE);
    } catch (PartInitException e) {
        MessageDialogHelper.openError(getSite().getShell(), Messages.get().MappingTables_Error, String.format(Messages.get().MappingTables_ErrorOpeningView, e.getLocalizedMessage()));
    }
}
Also used : MappingTableDescriptor(org.netxms.client.mt.MappingTableDescriptor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with MappingTableDescriptor

use of org.netxms.client.mt.MappingTableDescriptor in project netxms by netxms.

the class MappingTables method createNewTable.

/**
 * Create new table
 */
private void createNewTable() {
    final CreateMappingTableDialog dlg = new CreateMappingTableDialog(getSite().getShell());
    if (dlg.open() != Window.OK)
        return;
    new ConsoleJob(Messages.get().MappingTables_CreateJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Integer assignedId = session.createMappingTable(dlg.getName(), dlg.getDescription(), 0);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    // descriptor may already be presented if creation notification
                    // was already processed
                    MappingTableDescriptor d = mappingTables.get(assignedId);
                    if (d == null) {
                        d = new MappingTableDescriptor(assignedId, dlg.getName(), dlg.getDescription(), 0);
                        mappingTables.put(assignedId, d);
                    }
                    viewer.setInput(mappingTables.values().toArray());
                    viewer.setSelection(new StructuredSelection(d));
                    editTable();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            // TODO Auto-generated method stub
            return null;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MappingTableDescriptor(org.netxms.client.mt.MappingTableDescriptor) CreateMappingTableDialog(org.netxms.ui.eclipse.serverconfig.dialogs.CreateMappingTableDialog) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with MappingTableDescriptor

use of org.netxms.client.mt.MappingTableDescriptor in project netxms by netxms.

the class MappingTables method deleteTables.

/**
 * Delete selected tables
 */
private void deleteTables() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if ((selection == null) || (selection.size() == 0))
        return;
    if (!MessageDialogHelper.openQuestion(getSite().getShell(), Messages.get().MappingTables_DeleteConfirmation, Messages.get().MappingTables_DeleteConfirmationText))
        return;
    final List<Integer> tables = new ArrayList<Integer>(selection.size());
    for (Object o : selection.toList()) {
        if (o instanceof MappingTableDescriptor)
            tables.add(((MappingTableDescriptor) o).getId());
    }
    new ConsoleJob(Messages.get().MappingTables_DeleteJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            for (Integer id : tables) session.deleteMappingTable(id);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    for (Integer id : tables) mappingTables.remove(id);
                    viewer.setInput(mappingTables.values().toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().MappingTables_DeleteJobError;
        }
    }.start();
}
Also used : MappingTableDescriptor(org.netxms.client.mt.MappingTableDescriptor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

MappingTableDescriptor (org.netxms.client.mt.MappingTableDescriptor)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 PartInitException (org.eclipse.ui.PartInitException)3 ArrayList (java.util.ArrayList)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 NXCPMessage (org.netxms.base.NXCPMessage)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1 CreateMappingTableDialog (org.netxms.ui.eclipse.serverconfig.dialogs.CreateMappingTableDialog)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1