Search in sources :

Example 1 with SetEditor

use of org.netxms.ui.eclipse.widgets.SetEditor 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

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 ObjectLabelComparator (org.netxms.ui.eclipse.tools.ObjectLabelComparator)1 SetEditor (org.netxms.ui.eclipse.widgets.SetEditor)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1