use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.
the class TableColumns method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = (Composite) super.createContents(parent);
dci = editor.getObjectAsTable();
editor.setCallback(new TableColumnDataProvider());
columns = new ArrayList<ColumnDefinition>();
for (ColumnDefinition c : dci.getColumns()) columns.add(new ColumnDefinition(c));
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
Composite columnListArea = new Composite(dialogArea, SWT.NONE);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.horizontalSpan = 2;
columnListArea.setLayoutData(gd);
layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.INNER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 2;
columnListArea.setLayout(layout);
new Label(columnListArea, SWT.NONE).setText(Messages.get().TableColumns_Columns);
columnList = new TableViewer(columnListArea, 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.horizontalSpan = 2;
columnList.getControl().setLayoutData(gd);
setupColumnList();
columnList.setInput(columns.toArray());
Composite leftButtons = new Composite(columnListArea, SWT.NONE);
gd = new GridData();
gd.horizontalAlignment = SWT.LEFT;
leftButtons.setLayoutData(gd);
RowLayout buttonsLayout = new RowLayout(SWT.HORIZONTAL);
buttonsLayout.marginBottom = 0;
buttonsLayout.marginLeft = 0;
buttonsLayout.marginRight = 0;
buttonsLayout.marginTop = 0;
buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
buttonsLayout.fill = true;
buttonsLayout.pack = false;
leftButtons.setLayout(buttonsLayout);
upButton = new Button(leftButtons, SWT.PUSH);
upButton.setText(Messages.get().TableColumns_Up);
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
upButton.setLayoutData(rd);
upButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectionUp();
}
});
downButton = new Button(leftButtons, SWT.PUSH);
downButton.setText(Messages.get().TableColumns_Down);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
downButton.setLayoutData(rd);
downButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveSelectionDown();
}
});
Composite buttons = new Composite(columnListArea, SWT.NONE);
gd = new GridData();
gd.horizontalAlignment = SWT.RIGHT;
buttons.setLayoutData(gd);
buttonsLayout = new RowLayout(SWT.HORIZONTAL);
buttonsLayout.marginBottom = 0;
buttonsLayout.marginLeft = 0;
buttonsLayout.marginRight = 0;
buttonsLayout.marginTop = 0;
buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
buttonsLayout.fill = true;
buttonsLayout.pack = false;
buttons.setLayout(buttonsLayout);
queryButton = new Button(buttons, SWT.PUSH);
queryButton.setText("&Query...");
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
queryButton.setLayoutData(rd);
queryButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
queryColumns();
}
});
addButton = new Button(buttons, SWT.PUSH);
addButton.setText(Messages.get().TableColumns_Add);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
addButton.setLayoutData(rd);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
addColumn();
}
});
modifyButton = new Button(buttons, SWT.PUSH);
modifyButton.setText(Messages.get().TableColumns_Edit);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
modifyButton.setLayoutData(rd);
modifyButton.setEnabled(false);
modifyButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
editColumn();
}
});
deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().TableColumns_Delete);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
deleteButton.setLayoutData(rd);
deleteButton.setEnabled(false);
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
deleteColumns();
}
});
/**
* Selection change listener for column list **
*/
columnList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
deleteButton.setEnabled(selection.size() > 0);
if (selection.size() == 1) {
modifyButton.setEnabled(true);
upButton.setEnabled(columns.indexOf(selection.getFirstElement()) > 0);
downButton.setEnabled(columns.indexOf(selection.getFirstElement()) < columns.size() - 1);
} else {
modifyButton.setEnabled(false);
upButton.setEnabled(false);
downButton.setEnabled(false);
}
}
});
columnList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editColumn();
}
});
final DataCollectionObjectListener listener = new DataCollectionObjectListener() {
@Override
public void onSelectItem(int origin, String name, String description, DataType dataType) {
}
@Override
public void onSelectTable(int origin, String name, String description) {
if (origin == DataCollectionObject.AGENT)
updateColumnsFromAgent(name, false, null);
}
};
dialogArea.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
editor.removeListener(listener);
}
});
editor.addListener(listener);
return dialogArea;
}
use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.
the class TableColumns method updateColumnsFromAgent.
/**
* Update columns from real table
*/
private void updateColumnsFromAgent(final String name, final boolean interactive, final AbstractObject queryObject) {
final NXCSession session = ConsoleSharedData.getSession();
ConsoleJob job = new ConsoleJob(Messages.get().TableColumns_JobName, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
try {
final org.netxms.client.Table table;
if (editor.getSourceNode() != 0) {
table = session.queryAgentTable(editor.getSourceNode(), name);
} else {
table = session.queryAgentTable((queryObject != null) ? queryObject.getObjectId() : dci.getNodeId(), name);
}
runInUIThread(new Runnable() {
@Override
public void run() {
columns.clear();
for (int i = 0; i < table.getColumnCount(); i++) {
ColumnDefinition c = new ColumnDefinition(table.getColumnName(i), table.getColumnDisplayName(i));
c.setDataType(table.getColumnDefinition(i).getDataType());
c.setInstanceColumn(table.getColumnDefinition(i).isInstanceColumn());
columns.add(c);
}
columnList.setInput(columns.toArray());
}
});
} catch (Exception e) {
Activator.logError("Cannot read table column definition from agent", e);
if (interactive) {
final String msg = (e instanceof NXCException) ? e.getLocalizedMessage() : "Internal error";
runInUIThread(new Runnable() {
@Override
public void run() {
MessageDialogHelper.openError(getShell(), "Error", String.format("Cannot read table column definition from agent (%s)", msg));
}
});
}
}
}
@Override
protected String getErrorMessage() {
return null;
}
};
job.setUser(false);
job.start();
}
use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.
the class TableColumns method editColumn.
/**
* Edit selected threshold
*/
private void editColumn() {
final IStructuredSelection selection = (IStructuredSelection) columnList.getSelection();
if (selection.size() == 1) {
final ColumnDefinition column = (ColumnDefinition) selection.getFirstElement();
EditColumnDialog dlg = new EditColumnDialog(getShell(), column);
if (dlg.open() == Window.OK) {
columnList.update(column, null);
}
}
}
use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.
the class TableColumns method addColumn.
/**
* Add new threshold
*/
private void addColumn() {
final InputDialog idlg = new InputDialog(getShell(), Messages.get().TableColumns_NewColumn, Messages.get().TableColumns_ColumnName, "", new // $NON-NLS-1$
IInputValidator() {
@Override
public String isValid(String newText) {
if (newText.trim().isEmpty())
return Messages.get().TableColumns_WarningText;
return null;
}
});
if (idlg.open() == Window.OK) {
final ColumnDefinition column = new ColumnDefinition(idlg.getValue(), idlg.getValue());
final EditColumnDialog dlg = new EditColumnDialog(getShell(), column);
if (dlg.open() == Window.OK) {
columns.add(column);
columnList.setInput(columns.toArray());
columnList.setSelection(new StructuredSelection(column));
}
}
}
use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.
the class TableColumns method moveSelectionDown.
/**
* Move selected element down
*/
private void moveSelectionDown() {
final IStructuredSelection selection = (IStructuredSelection) columnList.getSelection();
if (selection.size() != 1)
return;
final ColumnDefinition column = (ColumnDefinition) selection.getFirstElement();
int index = columns.indexOf(column);
if (index < columns.size() - 1) {
Collections.swap(columns, index, index + 1);
columnList.setInput(columns.toArray());
columnList.setSelection(new StructuredSelection(column));
}
}
Aggregations