Search in sources :

Example 1 with InputFieldLabelProvider

use of org.netxms.ui.eclipse.objecttools.propertypages.helpers.InputFieldLabelProvider in project netxms by netxms.

the class InputFields method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    objectTool = (ObjectToolDetails) getElement().getAdapter(ObjectToolDetails.class);
    for (InputField f : objectTool.getInputFields()) fields.add(new InputField(f));
    Composite dialogArea = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT * 6;
    viewer.getTable().setLayoutData(gd);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new InputFieldLabelProvider());
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((InputField) e1).getSequence() - ((InputField) e2).getSequence();
        }
    });
    setupTableColumns();
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

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

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editField();
        }
    });
    viewer.setInput(fields.toArray());
    Composite buttonsLeft = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonsLeft.setLayout(buttonLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    gd.verticalIndent = WidgetHelper.OUTER_SPACING - WidgetHelper.INNER_SPACING;
    buttonsLeft.setLayoutData(gd);
    buttonUp = new Button(buttonsLeft, SWT.PUSH);
    buttonUp.setText(Messages.get().InputFields_Up);
    buttonUp.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveFieldUp();
        }
    });
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonUp.setLayoutData(rd);
    buttonUp.setEnabled(false);
    buttonDown = new Button(buttonsLeft, SWT.PUSH);
    buttonDown.setText(Messages.get().InputFields_Down);
    buttonDown.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveFieldDown();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonDown.setLayoutData(rd);
    buttonDown.setEnabled(false);
    Composite buttonsRight = new Composite(dialogArea, SWT.NONE);
    buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonsRight.setLayout(buttonLayout);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.verticalIndent = WidgetHelper.OUTER_SPACING - WidgetHelper.INNER_SPACING;
    buttonsRight.setLayoutData(gd);
    buttonAdd = new Button(buttonsRight, SWT.PUSH);
    buttonAdd.setText(Messages.get().Columns_Add);
    buttonAdd.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            addField();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonAdd.setLayoutData(rd);
    buttonEdit = new Button(buttonsRight, SWT.PUSH);
    buttonEdit.setText(Messages.get().Columns_Edit);
    buttonEdit.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            editField();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonEdit.setLayoutData(rd);
    buttonEdit.setEnabled(false);
    buttonRemove = new Button(buttonsRight, SWT.PUSH);
    buttonRemove.setText(Messages.get().Columns_Delete);
    buttonRemove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeField();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonRemove.setLayoutData(rd);
    buttonRemove.setEnabled(false);
    return dialogArea;
}
Also used : InputField(org.netxms.client.objecttools.InputField) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) InputFieldLabelProvider(org.netxms.ui.eclipse.objecttools.propertypages.helpers.InputFieldLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) 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) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

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 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)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 InputField (org.netxms.client.objecttools.InputField)1 InputFieldLabelProvider (org.netxms.ui.eclipse.objecttools.propertypages.helpers.InputFieldLabelProvider)1