Search in sources :

Example 36 with SortableTableViewer

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

the class DashboardElements method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (Dashboard) getElement().getAdapter(Dashboard.class);
    if (// Paranoid check
    object == null)
        return dialogArea;
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    columnCount = new LabeledSpinner(dialogArea, SWT.NONE);
    columnCount.setLabel(Messages.get().DashboardElements_NumColumns);
    columnCount.setRange(1, 128);
    columnCount.setSelection(object.getNumColumns());
    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.LEFT;
    gridData.horizontalSpan = 2;
    columnCount.setLayoutData(gridData);
    final String[] columnNames = { Messages.get().DashboardElements_Type, Messages.get().DashboardElements_Span, "Height" };
    final int[] columnWidths = { 150, 60, 90 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DashboardElementsLabelProvider());
    elements = copyElements(object.getElements());
    viewer.setInput(elements.toArray());
    gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    gridData.horizontalSpan = 2;
    viewer.getControl().setLayoutData(gridData);
    Composite leftButtons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginLeft = 0;
    leftButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gridData);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().DashboardElements_Up);
    upButton.setEnabled(false);
    upButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().DashboardElements_Down);
    downButton.setEnabled(false);
    downButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    Composite rightButtons = new Composite(dialogArea, SWT.NONE);
    buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    rightButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    rightButtons.setLayoutData(gridData);
    addButton = new Button(rightButtons, SWT.PUSH);
    addButton.setText(Messages.get().DashboardElements_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    editButton = new Button(rightButtons, SWT.PUSH);
    editButton.setText(Messages.get().DashboardElements_Edit);
    editButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    editXmlButton = new Button(rightButtons, SWT.PUSH);
    editXmlButton.setText(Messages.get().DashboardElements_EditXML);
    editXmlButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    deleteButton = new Button(rightButtons, SWT.PUSH);
    deleteButton.setText(Messages.get().DashboardElements_Delete);
    deleteButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            int index = elements.indexOf(selection.getFirstElement());
            upButton.setEnabled((selection.size() == 1) && (index > 0));
            downButton.setEnabled((selection.size() == 1) && (index >= 0) && (index < elements.size() - 1));
            editButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editButton.notifyListeners(SWT.Selection, new Event());
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DashboardElementsLabelProvider(org.netxms.ui.eclipse.dashboard.propertypages.helpers.DashboardElementsLabelProvider) LabeledSpinner(org.netxms.ui.eclipse.widgets.LabeledSpinner) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 37 with SortableTableViewer

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

the class DciSummaryTable method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    config = (DciSummaryTableConfig) getElement().getAdapter(DciSummaryTableConfig.class);
    Composite dialogArea = new Composite(parent, SWT.NONE);
    currSortingList = config.getSortingColumnList();
    GridLayout layout = new GridLayout();
    dialogArea.setLayout(layout);
    objectSelector = new ObjectSelector(dialogArea, SWT.NONE, true);
    objectSelector.setLabel(Messages.get().DciSummaryTable_BaseObject);
    objectSelector.setObjectClass(AbstractObject.class);
    objectSelector.setObjectId(config.getBaseObjectId());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    objectSelector.setLayoutData(gd);
    tableSelector = new SummaryTableSelector(dialogArea, SWT.NONE, AbstractSelector.SHOW_CLEAR_BUTTON);
    tableSelector.setLabel(Messages.get().DciSummaryTable_SummaryTable);
    tableSelector.setTableId(config.getTableId());
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    tableSelector.setLayoutData(gd);
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    refreshInterval = WidgetHelper.createLabeledSpinner(dialogArea, SWT.BORDER, Messages.get().DciSummaryTable_RefreshInterval, 0, 10000, gd);
    refreshInterval.setSelection(config.getRefreshInterval());
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    checkShowSortAndLimitFields = new Button(dialogArea, SWT.CHECK);
    checkShowSortAndLimitFields.setText("Show top N nodes");
    checkShowSortAndLimitFields.setSelection(config.isEnableSortingAndLineLimit());
    checkShowSortAndLimitFields.setLayoutData(gd);
    checkShowSortAndLimitFields.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (checkShowSortAndLimitFields.getSelection()) {
                sortTables.setSelection(null);
                buttonAdd.setEnabled(true);
                numRowsShow.setEnabled(true);
            } else {
                buttonUp.setEnabled(false);
                buttonDown.setEnabled(false);
                buttonEdit.setEnabled(false);
                buttonRemove.setEnabled(false);
                buttonAdd.setEnabled(false);
                numRowsShow.setEnabled(false);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Composite showTopNNodes = new Composite(dialogArea, SWT.BORDER);
    layout = new GridLayout();
    showTopNNodes.setLayout(layout);
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    numRowsShow = WidgetHelper.createLabeledSpinner(showTopNNodes, SWT.BORDER, "Number of lines to show", 0, 10000, gd);
    numRowsShow.setSelection(config.getNumRowShown());
    numRowsShow.setEnabled(config.isEnableSortingAndLineLimit());
    Label label = new Label(showTopNNodes, SWT.NONE);
    label.setText("Sort by columns");
    final String[] columnNames = { "Name", "Sort order" };
    final int[] columnWidths = { 320, 120 };
    sortTables = new SortableTableViewer(showTopNNodes, columnNames, columnWidths, 0, 0, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.verticalSpan = 2;
    gd.heightHint = 150;
    sortTables.getTable().setLayoutData(gd);
    sortTables.setContentProvider(new ArrayContentProvider());
    sortTables.setLabelProvider(new SortColumnTableLabelProvider());
    sortTables.setInput(currSortingList);
    sortTables.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (checkShowSortAndLimitFields.getSelection()) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                int index = currSortingList.indexOf(selection.getFirstElement());
                buttonUp.setEnabled((selection.size() == 1) && (index > 0));
                buttonDown.setEnabled((selection.size() == 1) && (index >= 0) && (index < currSortingList.size() - 1));
                buttonEdit.setEnabled(selection.size() == 1);
                buttonRemove.setEnabled(selection.size() > 0);
            } else {
                buttonUp.setEnabled(false);
                buttonDown.setEnabled(false);
                buttonEdit.setEnabled(false);
                buttonRemove.setEnabled(false);
            }
        }
    });
    sortTables.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            buttonEdit.notifyListeners(SWT.Selection, new Event());
        }
    });
    Composite buttons = new Composite(showTopNNodes, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    buttons.setLayoutData(gd);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttons.setLayout(buttonLayout);
    buttonUp = new Button(buttons, SWT.PUSH);
    buttonUp.setText("UP");
    buttonUp.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonUp.setLayoutData(rd);
    buttonUp.setEnabled(false);
    buttonDown = new Button(buttons, SWT.PUSH);
    buttonDown.setText("Down");
    buttonDown.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonDown.setLayoutData(rd);
    buttonDown.setEnabled(false);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.verticalIndent = WidgetHelper.OUTER_SPACING - WidgetHelper.INNER_SPACING;
    buttons.setLayoutData(gd);
    buttonAdd = new Button(buttons, SWT.PUSH);
    buttonAdd.setText("Add");
    buttonAdd.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            add();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonAdd.setLayoutData(rd);
    buttonAdd.setEnabled(config.isEnableSortingAndLineLimit());
    buttonEdit = new Button(buttons, SWT.PUSH);
    buttonEdit.setText("Edit");
    buttonEdit.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            edit();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonEdit.setLayoutData(rd);
    buttonEdit.setEnabled(false);
    buttonRemove = new Button(buttons, SWT.PUSH);
    buttonRemove.setText("Delete");
    buttonRemove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            remove();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonRemove.setLayoutData(rd);
    buttonRemove.setEnabled(false);
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SortColumnTableLabelProvider(org.netxms.ui.eclipse.dashboard.propertypages.helpers.SortColumnTableLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SummaryTableSelector(org.netxms.ui.eclipse.datacollection.widgets.SummaryTableSelector) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ObjectSelector(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 38 with SortableTableViewer

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

the class AbstractSelectParamDlg 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;
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    dialogArea.setLayout(layout);
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText(selectTables ? Messages.get().AbstractSelectParamDlg_AvailTables : Messages.get().AbstractSelectParamDlg_AvailableParameters);
    filterText = new Text(dialogArea, SWT.BORDER);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    filterText.setLayoutData(gd);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            filter.setFilter(filterText.getText());
            viewer.refresh(false);
        }
    });
    final String[] names = { Messages.get().AbstractSelectParamDlg_Name, selectTables ? Messages.get().AbstractSelectParamDlg_InstanceColumn : Messages.get().AbstractSelectParamDlg_Type, Messages.get().AbstractSelectParamDlg_Description };
    final int[] widths = { 150, selectTables ? 150 : 100, 350 };
    viewer = new SortableTableViewer(dialogArea, names, widths, 0, SWT.UP, SWT.FULL_SELECTION | SWT.BORDER);
    // $NON-NLS-1$
    WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), getConfigurationPrefix() + ".viewer");
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(selectTables ? new AgentTableLabelProvider() : new AgentParameterLabelProvider());
    viewer.setComparator(selectTables ? new AgentTableComparator() : new AgentParameterComparator());
    filter = new AgentParameterFilter();
    viewer.addFilter(filter);
    viewer.getTable().addMouseListener(new MouseListener() {

        @Override
        public void mouseDoubleClick(MouseEvent e) {
            okPressed();
        }

        @Override
        public void mouseDown(MouseEvent e) {
        }

        @Override
        public void mouseUp(MouseEvent e) {
        }
    });
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), getConfigurationPrefix() + ".viewer");
        }
    });
    createPopupMenu();
    gd = new GridData();
    gd.heightHint = 250;
    gd.grabExcessVerticalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    viewer.getControl().setLayoutData(gd);
    fillParameterList();
    return dialogArea;
}
Also used : AgentTableComparator(org.netxms.ui.eclipse.datacollection.dialogs.helpers.AgentTableComparator) AgentParameterLabelProvider(org.netxms.ui.eclipse.datacollection.dialogs.helpers.AgentParameterLabelProvider) DisposeListener(org.eclipse.swt.events.DisposeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) AgentTableLabelProvider(org.netxms.ui.eclipse.datacollection.dialogs.helpers.AgentTableLabelProvider) Label(org.eclipse.swt.widgets.Label) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) Text(org.eclipse.swt.widgets.Text) DisposeEvent(org.eclipse.swt.events.DisposeEvent) AgentParameterFilter(org.netxms.ui.eclipse.datacollection.dialogs.helpers.AgentParameterFilter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) MouseListener(org.eclipse.swt.events.MouseListener) AgentParameterComparator(org.netxms.ui.eclipse.datacollection.dialogs.helpers.AgentParameterComparator) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider)

Example 39 with SortableTableViewer

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

the class SelectServerFileDialog 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;
    dialogArea.setLayout(layout);
    final String[] names = { Messages.get().SelectServerFileDialog_ColName, Messages.get().SelectServerFileDialog_ColSize, Messages.get().SelectServerFileDialog_ColModTime };
    final int[] widths = { 200, 100, 150 };
    viewer = new SortableTableViewer(dialogArea, names, widths, 0, SWT.DOWN, SWT.FULL_SELECTION | SWT.BORDER | (multiSelect ? SWT.MULTI : 0));
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new ServerFileLabelProvider());
    viewer.setComparator(new ServerFileComparator());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 450;
    viewer.getControl().setLayoutData(gd);
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            okPressed();
        }
    });
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().SelectServerFileDialog_JobTitle, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final ServerFile[] files = session.listServerFiles();
            runInUIThread(new Runnable() {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().SelectServerFileDialog_JobError;
        }
    }.start();
    return dialogArea;
}
Also used : NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ServerFileLabelProvider(org.netxms.ui.eclipse.filemanager.dialogs.helpers.ServerFileLabelProvider) ServerFileComparator(org.netxms.ui.eclipse.filemanager.dialogs.helpers.ServerFileComparator) 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) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 40 with SortableTableViewer

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

the class RulePStorage 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();
    pStorageDelete.addAll(rule.getPStorageDelete());
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final int vInd = WidgetHelper.OUTER_SPACING - WidgetHelper.INNER_SPACING;
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText("Set persistent storage values");
    GridData gd = new GridData();
    gd.verticalIndent = vInd;
    label.setLayoutData(gd);
    sEditor = new SetEditor(dialogArea, SWT.NONE);
    sEditor.putAll(rule.getPStorageSet());
    gd = new GridData();
    gd.verticalIndent = vInd;
    gd.verticalAlignment = GridData.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    sEditor.setLayoutData(gd);
    label = new Label(dialogArea, SWT.NONE);
    label.setText("Delete persistent storage entries");
    gd = new GridData();
    gd.verticalIndent = vInd;
    label.setLayoutData(gd);
    final String[] deleteColumnNames = { "Key" };
    final int[] deleteColumnWidths = { 150 };
    viewerDeleteValue = new SortableTableViewer(dialogArea, deleteColumnNames, deleteColumnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewerDeleteValue.setContentProvider(new ArrayContentProvider());
    viewerDeleteValue.setComparator(new ObjectLabelComparator((ILabelProvider) viewerDeleteValue.getLabelProvider()));
    viewerDeleteValue.setInput(pStorageDelete.toArray());
    viewerDeleteValue.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int size = ((IStructuredSelection) viewerDeleteValue.getSelection()).size();
            editDeleteValueButton.setEnabled(size == 1);
            removeDeleteValueButton.setEnabled(size > 0);
        }
    });
    gd = new GridData();
    gd.verticalAlignment = GridData.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    viewerDeleteValue.getControl().setLayoutData(gd);
    Composite buttonsDeleteValue = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginLeft = 0;
    buttonLayout.marginRight = 0;
    buttonsDeleteValue.setLayout(buttonLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttonsDeleteValue.setLayoutData(gd);
    addDeleteValueButton = new Button(buttonsDeleteValue, SWT.PUSH);
    addDeleteValueButton.setText("Add");
    addDeleteValueButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            addPStorageDeleteAction();
        }
    });
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addDeleteValueButton.setLayoutData(rd);
    editDeleteValueButton = new Button(buttonsDeleteValue, SWT.PUSH);
    editDeleteValueButton.setText("Edit");
    editDeleteValueButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            editPStorageDeleteAction();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    editDeleteValueButton.setLayoutData(rd);
    editDeleteValueButton.setEnabled(false);
    removeDeleteValueButton = new Button(buttonsDeleteValue, SWT.PUSH);
    removeDeleteValueButton.setText("Delete");
    removeDeleteValueButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            deletePStorageDeleteAction();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    removeDeleteValueButton.setLayoutData(rd);
    removeDeleteValueButton.setEnabled(false);
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SetEditor(org.netxms.ui.eclipse.widgets.SetEditor) ObjectLabelComparator(org.netxms.ui.eclipse.tools.ObjectLabelComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) 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) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) 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