use of org.netxms.ui.eclipse.dashboard.propertypages.helpers.DashboardElementsLabelProvider 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;
}
Aggregations