Search in sources :

Example 71 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class PackageComparator 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) {
    PackageInfo p1 = (PackageInfo) e1;
    PackageInfo p2 = (PackageInfo) e2;
    int result;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case PackageManager.COLUMN_ID:
            result = Long.signum(p1.getId() - p2.getId());
            break;
        case PackageManager.COLUMN_DESCRIPTION:
            result = p1.getDescription().compareToIgnoreCase(p2.getDescription());
            break;
        case PackageManager.COLUMN_FILE:
            result = p1.getFileName().compareToIgnoreCase(p2.getFileName());
            break;
        case PackageManager.COLUMN_NAME:
            result = p1.getName().compareToIgnoreCase(p2.getName());
            break;
        case PackageManager.COLUMN_PLATFORM:
            result = p1.getPlatform().compareToIgnoreCase(p2.getPlatform());
            break;
        case PackageManager.COLUMN_VERSION:
            result = p1.getVersion().compareToIgnoreCase(p2.getVersion());
            break;
        default:
            result = 0;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : PackageInfo(org.netxms.client.packages.PackageInfo) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 72 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class DataCollectionEditor method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    content = new Composite(parent, SWT.NONE);
    content.setLayout(new FormLayout());
    // Create filter area
    filterText = new FilterText(content, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    final String[] names = { Messages.get().DataCollectionEditor_ColID, Messages.get().DataCollectionEditor_ColOrigin, Messages.get().DataCollectionEditor_ColDescription, Messages.get().DataCollectionEditor_ColParameter, Messages.get().DataCollectionEditor_ColDataType, Messages.get().DataCollectionEditor_ColPollingInterval, Messages.get().DataCollectionEditor_ColRetentionTime, Messages.get().DataCollectionEditor_ColStatus, Messages.get().DataCollectionEditor_ColThresholds, Messages.get().DataCollectionEditor_ColTemplate };
    final int[] widths = { 60, 100, 250, 200, 90, 90, 90, 100, 200, 150 };
    viewer = new SortableTableViewer(content, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DciLabelProvider());
    viewer.setComparator(new DciComparator((DciLabelProvider) viewer.getLabelProvider()));
    filter = new DciFilter();
    viewer.addFilter(filter);
    // $NON-NLS-1$
    WidgetHelper.restoreTableViewerSettings(viewer, settings, "DataCollectionEditor");
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEdit.setEnabled(selection.size() == 1);
                actionDelete.setEnabled(selection.size() > 0);
                actionCopy.setEnabled(selection.size() > 0);
                actionMove.setEnabled(selection.size() > 0);
                actionConvert.setEnabled(selection.size() > 0);
                actionDuplicate.setEnabled(selection.size() > 0);
                Iterator<?> it = selection.iterator();
                boolean canActivate = false;
                boolean canDisable = false;
                while (it.hasNext() && (!canActivate || !canDisable)) {
                    DataCollectionObject dci = (DataCollectionObject) it.next();
                    if (dci.getStatus() != DataCollectionObject.ACTIVE)
                        canActivate = true;
                    if (dci.getStatus() != DataCollectionObject.DISABLED)
                        canDisable = true;
                }
                actionActivate.setEnabled(canActivate);
                actionDisable.setEnabled(canDisable);
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

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

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            WidgetHelper.saveTableViewerSettings(viewer, settings, "DataCollectionEditor");
            settings.put("DataCollectionEditor.hideModificationWarnings", hideModificationWarnings);
        }
    });
    // 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.getTable().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();
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
            actionShowFilter.setChecked(false);
        }
    });
    // Request server to open data collection configuration
    new ConsoleJob(Messages.get().DataCollectionEditor_OpenJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            dciConfig = session.openDataCollectionConfiguration(object.getObjectId());
            dciConfig.setUserData(viewer);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(dciConfig.getItems());
                }
            });
        }

        @Override
        protected void jobFailureHandler() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    DataCollectionEditor.this.getViewSite().getPage().hideView(DataCollectionEditor.this);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DataCollectionEditor_OpenJob_Error + object.getObjectName();
        }
    }.start();
    // Set initial focus to filter input line
    if (actionShowFilter.isChecked())
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
    hideModificationWarnings = getBooleanFromSettings("DataCollectionEditor.hideModificationWarnings", false);
    activateContext();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) 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) DciLabelProvider(org.netxms.ui.eclipse.datacollection.views.helpers.DciLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) FormAttachment(org.eclipse.swt.layout.FormAttachment) DciFilter(org.netxms.ui.eclipse.datacollection.views.helpers.DciFilter) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) DciComparator(org.netxms.ui.eclipse.datacollection.views.helpers.DciComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider)

Example 73 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class AgentParameterComparator 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;
    AgentParameter p1 = (AgentParameter) e1;
    AgentParameter p2 = (AgentParameter) e2;
    switch(// $NON-NLS-1$
    (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
        case AbstractSelectParamDlg.COLUMN_NAME:
            result = p1.getName().compareToIgnoreCase(p2.getName());
            break;
        case AbstractSelectParamDlg.COLUMN_TYPE:
            result = DataCollectionDisplayInfo.getDataTypeName(p1.getDataType()).compareTo(DataCollectionDisplayInfo.getDataTypeName(p2.getDataType()));
            break;
        case AbstractSelectParamDlg.COLUMN_DESCRIPTION:
            result = p1.getDescription().compareToIgnoreCase(p2.getDescription());
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) AgentParameter(org.netxms.client.AgentParameter)

Example 74 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class SummaryTableManager method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    // Create interface area
    tableArea = new Composite(parent, SWT.BORDER);
    FormLayout formLayout = new FormLayout();
    tableArea.setLayout(formLayout);
    // Create filter
    filterText = new FilterText(tableArea, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

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

        @Override
        public void widgetDisposed(DisposeEvent e) {
            settings.put("SummaryTableManager.showFilter", initShowFilter);
        }
    });
    final String[] names = { Messages.get().SummaryTableManager_ID, Messages.get().SummaryTableManager_MenuPath, Messages.get().SummaryTableManager_Title };
    final int[] widths = { 90, 250, 200 };
    viewer = new SortableTableViewer(tableArea, names, widths, COLUMN_MENU_PATH, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new SummaryTableLabelProvider());
    viewer.setComparator(new SummaryTableComparator());
    filter = new SummaryTableFilter();
    viewer.addFilter(filter);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            actionEdit.setEnabled(selection.size() == 1);
            actionDelete.setEnabled(selection.size() > 0);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editSummaryTable();
        }
    });
    // 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();
    filterText.setCloseAction(actionShowFilter);
    enableFilter(initShowFilter);
    refresh();
    listener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            if (n.getCode() == SessionNotification.DCI_SUMMARY_TABLE_DELETED) {
                final int id = (int) n.getSubCode();
                getSite().getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (descriptors.remove(id) != null)
                            viewer.setInput(descriptors.values().toArray());
                    }
                });
            } else if (n.getCode() == SessionNotification.DCI_SUMMARY_TABLE_UPDATED) {
                getSite().getShell().getDisplay().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refresh();
                    }
                });
            }
        }
    };
    session.addListener(listener);
    activateContext();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SummaryTableLabelProvider(org.netxms.ui.eclipse.datacollection.views.helpers.SummaryTableLabelProvider) 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) SessionNotification(org.netxms.client.SessionNotification) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) SummaryTableFilter(org.netxms.ui.eclipse.datacollection.views.helpers.SummaryTableFilter) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SummaryTableComparator(org.netxms.ui.eclipse.datacollection.views.helpers.SummaryTableComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SessionListener(org.netxms.client.SessionListener)

Example 75 with SortableTableViewer

use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.

the class RuleServerActions method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    editor = (RuleEditor) getElement().getAdapter(RuleEditor.class);
    rule = editor.getRule();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().RuleServerActions_Action };
    final int[] columnWidths = { 300 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new WorkbenchLabelProvider());
    viewer.setComparator(new ObjectLabelComparator((ILabelProvider) viewer.getLabelProvider()));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int size = ((IStructuredSelection) viewer.getSelection()).size();
            deleteButton.setEnabled(size > 0);
        }
    });
    actions.putAll(editor.getEditorView().findServerActions(rule.getActions()));
    viewer.setInput(actions.values().toArray());
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    viewer.getControl().setLayoutData(gridData);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginLeft = 0;
    buttonLayout.marginRight = 0;
    buttons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gridData);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().RuleServerActions_Add);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            addAction();
        }
    });
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().RuleServerActions_Delete);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteAction();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.setEnabled(false);
    return dialogArea;
}
Also used : WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) Composite(org.eclipse.swt.widgets.Composite) ObjectLabelComparator(org.netxms.ui.eclipse.tools.ObjectLabelComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)97 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)66 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)43 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)43 Composite (org.eclipse.swt.widgets.Composite)43 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)40 GridData (org.eclipse.swt.layout.GridData)38 GridLayout (org.eclipse.swt.layout.GridLayout)38 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)29 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)29 SelectionEvent (org.eclipse.swt.events.SelectionEvent)28 Button (org.eclipse.swt.widgets.Button)28 SelectionListener (org.eclipse.swt.events.SelectionListener)27 DisposeEvent (org.eclipse.swt.events.DisposeEvent)26 DisposeListener (org.eclipse.swt.events.DisposeListener)26 RowLayout (org.eclipse.swt.layout.RowLayout)24 RowData (org.eclipse.swt.layout.RowData)20 Event (org.eclipse.swt.widgets.Event)14 FillLayout (org.eclipse.swt.layout.FillLayout)12 Iterator (java.util.Iterator)11