Search in sources :

Example 1 with ObjectToolsComparator

use of org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsComparator in project netxms by netxms.

the class ObjectToolsEditor method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    // Initiate loading of required plugins if they was not loaded yet
    try {
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new AccessListElement(0, 0), "org.eclipse.ui.model.IWorkbenchAdapter");
    } catch (Exception e) {
    }
    // Create interface area
    objectToolsArea = new Composite(parent, SWT.BORDER);
    FormLayout formLayout = new FormLayout();
    objectToolsArea.setLayout(formLayout);
    // Create filter
    filterText = new FilterText(objectToolsArea, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
            actionShowFilter.setChecked(initShowFilter);
        }
    });
    final String[] columnNames = { Messages.get().ObjectToolsEditor_ColId, Messages.get().ObjectToolsEditor_ColName, Messages.get().ObjectToolsEditor_ColType, Messages.get().ObjectToolsEditor_ColDescr };
    final int[] columnWidths = { 90, 200, 100, 200 };
    viewer = new SortableTableViewer(objectToolsArea, columnNames, columnWidths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ObjectToolsLabelProvider());
    filter = new ObjectToolsFilter();
    viewer.addFilter(filter);
    viewer.setComparator(new ObjectToolsComparator());
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEdit.setEnabled(selection.size() == 1);
                actionClone.setEnabled(selection.size() == 1);
                actionDelete.setEnabled(selection.size() > 0);
                actionDisable.setEnabled(containsEnabled(selection));
                actionEnable.setEnabled(containsDisabled(selection));
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEdit.run();
        }
    });
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterText);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    viewer.getControl().setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    activateContext();
    session.addListener(this);
    // Set initial focus to filter input line
    if (initShowFilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
    refreshToolList();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PropertyDialogAction(org.eclipse.ui.dialogs.PropertyDialogAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ObjectToolsComparator(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsComparator) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ObjectToolsLabelProvider(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ObjectToolsFilter(org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsFilter)

Aggregations

Action (org.eclipse.jface.action.Action)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 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 PartInitException (org.eclipse.ui.PartInitException)1 PropertyDialogAction (org.eclipse.ui.dialogs.PropertyDialogAction)1 AccessListElement (org.netxms.client.AccessListElement)1 RefreshAction (org.netxms.ui.eclipse.actions.RefreshAction)1 ObjectToolsComparator (org.netxms.ui.eclipse.objecttools.views.helpers.ObjectToolsComparator)1