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;
}
Aggregations