Search in sources :

Example 1 with MappingTableListComparator

use of org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListComparator in project netxms by netxms.

the class MappingTables method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    final int[] widths = { 80, 160, 80, 400 };
    final String[] names = { Messages.get().MappingTables_ColID, Messages.get().MappingTables_ColName, Messages.get().MappingTables_ColFlags, Messages.get().MappingTables_ColDescription };
    viewer = new SortableTableViewer(parent, names, widths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new MappingTableListLabelProvider());
    viewer.setComparator(new MappingTableListComparator());
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editTable();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            actionEditTable.setEnabled(selection.size() == 1);
            actionDeleteTables.setEnabled(selection.size() > 0);
        }
    });
    final IDialogSettings settings = Activator.getDefault().getDialogSettings();
    // $NON-NLS-1$
    WidgetHelper.restoreTableViewerSettings(viewer, settings, "MappingTablesList");
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            WidgetHelper.saveTableViewerSettings(viewer, settings, "MappingTablesList");
        }
    });
    createActions();
    contributeToActionBars();
    createPopupMenu();
    session = ConsoleSharedData.getSession();
    refresh(0);
    final Display display = getSite().getShell().getDisplay();
    listener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() == SessionNotification.MAPPING_TABLE_UPDATED) {
                final Integer id = (int) n.getSubCode();
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refresh(id);
                    }
                });
            } else if (n.getCode() == SessionNotification.MAPPING_TABLE_DELETED) {
                final Integer id = (int) n.getSubCode();
                display.asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        mappingTables.remove(id);
                        viewer.setInput(mappingTables.values().toArray());
                    }
                });
            }
        }
    };
    session.addListener(listener);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener) MappingTableListLabelProvider(org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListLabelProvider) SessionNotification(org.netxms.client.SessionNotification) MappingTableListComparator(org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListComparator) Display(org.eclipse.swt.widgets.Display)

Aggregations

IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 Display (org.eclipse.swt.widgets.Display)1 SessionListener (org.netxms.client.SessionListener)1 SessionNotification (org.netxms.client.SessionNotification)1 MappingTableListComparator (org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListComparator)1 MappingTableListLabelProvider (org.netxms.ui.eclipse.serverconfig.views.helpers.MappingTableListLabelProvider)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1