use of org.netxms.ui.eclipse.datacollection.views.helpers.DciFilter in project netxms by netxms.
the class DataCollectionEditor method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
content = new Composite(parent, SWT.NONE);
content.setLayout(new FormLayout());
// Create filter area
filterText = new FilterText(content, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
final String[] names = { Messages.get().DataCollectionEditor_ColID, Messages.get().DataCollectionEditor_ColOrigin, Messages.get().DataCollectionEditor_ColDescription, Messages.get().DataCollectionEditor_ColParameter, Messages.get().DataCollectionEditor_ColDataType, Messages.get().DataCollectionEditor_ColPollingInterval, Messages.get().DataCollectionEditor_ColRetentionTime, Messages.get().DataCollectionEditor_ColStatus, Messages.get().DataCollectionEditor_ColThresholds, Messages.get().DataCollectionEditor_ColTemplate };
final int[] widths = { 60, 100, 250, 200, 90, 90, 90, 100, 200, 150 };
viewer = new SortableTableViewer(content, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new DciLabelProvider());
viewer.setComparator(new DciComparator((DciLabelProvider) viewer.getLabelProvider()));
filter = new DciFilter();
viewer.addFilter(filter);
// $NON-NLS-1$
WidgetHelper.restoreTableViewerSettings(viewer, settings, "DataCollectionEditor");
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null) {
actionEdit.setEnabled(selection.size() == 1);
actionDelete.setEnabled(selection.size() > 0);
actionCopy.setEnabled(selection.size() > 0);
actionMove.setEnabled(selection.size() > 0);
actionConvert.setEnabled(selection.size() > 0);
actionDuplicate.setEnabled(selection.size() > 0);
Iterator<?> it = selection.iterator();
boolean canActivate = false;
boolean canDisable = false;
while (it.hasNext() && (!canActivate || !canDisable)) {
DataCollectionObject dci = (DataCollectionObject) it.next();
if (dci.getStatus() != DataCollectionObject.ACTIVE)
canActivate = true;
if (dci.getStatus() != DataCollectionObject.DISABLED)
canDisable = true;
}
actionActivate.setEnabled(canActivate);
actionDisable.setEnabled(canDisable);
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
actionEdit.run();
}
});
viewer.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
// $NON-NLS-1$
WidgetHelper.saveTableViewerSettings(viewer, settings, "DataCollectionEditor");
settings.put("DataCollectionEditor.hideModificationWarnings", hideModificationWarnings);
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterText);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
viewer.getTable().setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterText.setLayoutData(fd);
createActions();
contributeToActionBars();
createPopupMenu();
filterText.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
actionShowFilter.setChecked(false);
}
});
// Request server to open data collection configuration
new ConsoleJob(Messages.get().DataCollectionEditor_OpenJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
dciConfig = session.openDataCollectionConfiguration(object.getObjectId());
dciConfig.setUserData(viewer);
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.setInput(dciConfig.getItems());
}
});
}
@Override
protected void jobFailureHandler() {
runInUIThread(new Runnable() {
@Override
public void run() {
DataCollectionEditor.this.getViewSite().getPage().hideView(DataCollectionEditor.this);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().DataCollectionEditor_OpenJob_Error + object.getObjectName();
}
}.start();
// Set initial focus to filter input line
if (actionShowFilter.isChecked())
filterText.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
hideModificationWarnings = getBooleanFromSettings("DataCollectionEditor.hideModificationWarnings", false);
activateContext();
}
Aggregations