Search in sources :

Example 21 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project netxms by netxms.

the class ActionSelectionDialog method createDialogArea.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createDialogArea(Composite parent) {
    final Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ActionSelectionDialogLabelProvider());
    viewer.setComparator(new ViewerComparator() {

        /* (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) {
            return ((ServerAction) e1).getName().compareToIgnoreCase(((ServerAction) e2).getName());
        }
    });
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob("Get server actions", null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<ServerAction> list = session.getActions();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(list.toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot get server actions";
        }
    }.start();
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 400;
    viewer.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : ActionSelectionDialogLabelProvider(org.netxms.ui.eclipse.actionmanager.dialogs.helpers.ActionSelectionDialogLabelProvider) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) ServerAction(org.netxms.client.ServerAction)

Example 22 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project netxms by netxms.

the class WinPerfCounterSelectionDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.horizontalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    dialogArea.setLayout(layout);
    new Label(dialogArea, SWT.NONE).setText(Messages.get().WinPerfCounterSelectionDialog_ObjectsAndCounters);
    new Label(dialogArea, SWT.NONE).setText(Messages.get().WinPerfCounterSelectionDialog_Instances);
    objectTree = new TreeViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 400;
    gd.widthHint = 350;
    objectTree.getControl().setLayoutData(gd);
    objectTree.setContentProvider(new WinPerfObjectTreeContentProvider());
    objectTree.setLabelProvider(new WinPerfObjectTreeLabelProvider());
    objectTree.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            String s1 = (e1 instanceof WinPerfCounter) ? ((WinPerfCounter) e1).getName() : ((WinPerfObject) e1).getName();
            String s2 = (e2 instanceof WinPerfCounter) ? ((WinPerfCounter) e2).getName() : ((WinPerfObject) e2).getName();
            return s1.compareToIgnoreCase(s2);
        }
    });
    objectTree.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            onObjectSelection();
        }
    });
    instanceList = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.widthHint = 350;
    instanceList.getControl().setLayoutData(gd);
    instanceList.setContentProvider(new ArrayContentProvider());
    instanceList.setLabelProvider(new LabelProvider());
    instanceList.setComparator(new StringComparator());
    fillData();
    return dialogArea;
}
Also used : WinPerfObjectTreeLabelProvider(org.netxms.ui.eclipse.datacollection.dialogs.helpers.WinPerfObjectTreeLabelProvider) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) WinPerfObject(org.netxms.client.datacollection.WinPerfObject) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StringComparator(org.netxms.ui.eclipse.tools.StringComparator) GridLayout(org.eclipse.swt.layout.GridLayout) WinPerfCounter(org.netxms.client.datacollection.WinPerfCounter) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) WinPerfObject(org.netxms.client.datacollection.WinPerfObject) TableViewer(org.eclipse.jface.viewers.TableViewer) WinPerfObjectTreeLabelProvider(org.netxms.ui.eclipse.datacollection.dialogs.helpers.WinPerfObjectTreeLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) WinPerfObjectTreeContentProvider(org.netxms.ui.eclipse.datacollection.dialogs.helpers.WinPerfObjectTreeContentProvider)

Example 23 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project netxms by netxms.

the class StartServerToAgentFileUploadDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    dialogArea.setLayout(layout);
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText(Messages.get().StartServerToAgentFileUploadDialog_ServerFile);
    fileList = new TableViewer(dialogArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.widthHint = 400;
    gd.heightHint = 150;
    fileList.getControl().setLayoutData(gd);
    fileList.setContentProvider(new ArrayContentProvider());
    fileList.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ServerFile) element).getName();
        }
    });
    fileList.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((ServerFile) e1).getName().compareToIgnoreCase(((ServerFile) e2).getName());
        }
    });
    fileList.setInput(serverFiles);
    Composite buttonArea = new Composite(dialogArea, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    buttonArea.setLayout(layout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttonArea.setLayoutData(gd);
    buttonAddFile = new Button(buttonArea, SWT.PUSH);
    buttonAddFile.setText("&Add...");
    gd = new GridData();
    gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonAddFile.setLayoutData(gd);
    buttonAddFile.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            SelectServerFileDialog dlg = new SelectServerFileDialog(getShell(), true);
            if (dlg.open() == Window.OK) {
                for (ServerFile f : dlg.getSelectedFiles()) {
                    boolean found = false;
                    for (ServerFile sf : serverFiles) if (sf.getName().equals(f.getName())) {
                        found = true;
                        break;
                    }
                    if (!found)
                        serverFiles.add(f);
                }
                fileList.refresh();
            }
        }
    });
    buttonRemoveFile = new Button(buttonArea, SWT.PUSH);
    buttonRemoveFile.setText("&Remove");
    gd = new GridData();
    gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonRemoveFile.setLayoutData(gd);
    buttonRemoveFile.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) fileList.getSelection();
            for (Object o : selection.toList()) serverFiles.remove(o);
            fileList.refresh();
        }
    });
    textRemoteFile = new LabeledText(dialogArea, SWT.NONE);
    textRemoteFile.setLabel(Messages.get().StartServerToAgentFileUploadDialog_RemoteFileName);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    textRemoteFile.setLayoutData(gd);
    checkJobOnHold = new Button(dialogArea, SWT.CHECK);
    checkJobOnHold.setText(Messages.get().StartServerToAgentFileUploadDialog_CreateJobOnHold);
    checkJobOnHold.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            checkIsSchedule.setEnabled(!checkJobOnHold.getSelection());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    if (canScheduleFileUpload) {
        checkIsSchedule = new Button(dialogArea, SWT.CHECK);
        checkIsSchedule.setText(Messages.get().StartServerToAgentFileUploadDialog_ScheduleTask);
        checkIsSchedule.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                checkJobOnHold.setEnabled(!checkIsSchedule.getSelection());
                scheduleSelector.setEnabled(checkIsSchedule.getSelection());
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
                widgetSelected(e);
            }
        });
        scheduleSelector = new ScheduleSelector(dialogArea, SWT.NONE);
        scheduleSelector.setEnabled(false);
    }
    return dialogArea;
}
Also used : ScheduleSelector(org.netxms.ui.eclipse.widgets.ScheduleSelector) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ServerFile(org.netxms.client.server.ServerFile) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 24 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project netxms by netxms.

the class SelectScriptDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    dialogArea.setLayout(layout);
    new Label(dialogArea, SWT.NONE).setText(Messages.get().SelectScriptDialog_AvailableScripts);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | (multiSelection ? SWT.MULTI : 0));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((Script) element).getName();
        }
    });
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            Script s1 = (Script) e1;
            Script s2 = (Script) e2;
            return s1.getName().compareToIgnoreCase(s2.getName());
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            SelectScriptDialog.this.okPressed();
        }
    });
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    gd.widthHint = 400;
    viewer.getControl().setLayoutData(gd);
    final NXCSession session = ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SelectScriptDialog_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<Script> scripts = session.getScriptLibrary();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(scripts.toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SelectScriptDialog_JobError;
        }
    }.start();
    return dialogArea;
}
Also used : Script(org.netxms.client.Script) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 25 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project netxms by netxms.

the class NetworkMapWidget method setLayoutAlgorithm.

/**
 * Set layout algorithm for map
 * @param alg
 */
public void setLayoutAlgorithm(MapLayoutAlgorithm alg) {
    LayoutAlgorithm algorithm;
    switch(alg) {
        case SPRING:
            algorithm = new SpringLayoutAlgorithm();
            break;
        case RADIAL:
            algorithm = new RadialLayoutAlgorithm();
            break;
        case HTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
            break;
        case VTREE:
            algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
            break;
        case SPARSE_VTREE:
            TreeLayoutAlgorithm mainLayoutAlgorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
            viewer.setComparator(new ViewerComparator() {

                @Override
                public int compare(Viewer viewer, Object e1, Object e2) {
                    return e1.toString().compareToIgnoreCase(e2.toString());
                }
            });
            algorithm = new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { mainLayoutAlgorithm, new SparseTree() });
            break;
        default:
            algorithm = new GridLayoutAlgorithm();
            break;
    }
    viewer.setLayoutAlgorithm(algorithm);
}
Also used : SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) SparseTree(org.netxms.ui.eclipse.networkmaps.algorithms.SparseTree) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) MapLayoutAlgorithm(org.netxms.client.maps.MapLayoutAlgorithm) LayoutAlgorithm(org.eclipse.gef4.zest.layouts.LayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) ExtendedGraphViewer(org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer) Viewer(org.eclipse.jface.viewers.Viewer) AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)

Aggregations

ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)110 Viewer (org.eclipse.jface.viewers.Viewer)64 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)50 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)34 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)23 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)18 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)17 Button (org.eclipse.swt.widgets.Button)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)15 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)15