use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.
the class PredefinedGraphTree method editPredefinedGraph.
/**
* Edit predefined graph
*/
private void editPredefinedGraph() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 1)
return;
GraphSettings settings = (GraphSettings) selection.getFirstElement();
PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, settings);
if (dlg != null) {
if (dlg.open() == Window.OK) {
final GraphSettings newSettings = settings;
try {
new ConsoleJob(Messages.get().PredefinedGraphTree_UpdateJobName, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.saveGraph(newSettings, true);
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.update(newSettings, null);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().PredefinedGraphTree_UpdateJobError;
}
}.start();
} catch (Exception e) {
// $NON-NLS-1$ //$NON-NLS-2$
MessageDialogHelper.openError(getSite().getShell(), "Internal Error", String.format("Unexpected exception: %s", e.getLocalizedMessage()));
}
}
}
}
use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.
the class PredefinedGraphTree method onFilterModify.
/**
* Handler for filter modification
*/
private void onFilterModify() {
final String text = filterText.getText();
filter.setFilterString(text);
viewer.refresh(false);
GraphSettings s = filter.getLastMatch();
if (s != null) {
viewer.expandToLevel(s, 1);
viewer.setSelection(new StructuredSelection(s), true);
}
}
use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.
the class PredefinedGraphTree method createActions.
/**
* Create actions
*/
private void createActions() {
final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
actionRefresh = new RefreshAction(this) {
@Override
public void run() {
reloadGraphList();
}
};
actionDelete = new Action(Messages.get().PredefinedGraphTree_Delete, SharedIcons.DELETE_OBJECT) {
@Override
public void run() {
deletePredefinedGraph();
}
};
actionOpen = new Action() {
@SuppressWarnings("rawtypes")
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Iterator it = selection.iterator();
while (it.hasNext()) {
Object o = it.next();
if (o instanceof GraphSettings) {
showPredefinedGraph((GraphSettings) o);
}
}
}
};
actionOpen.setText(Messages.get().PredefinedGraphTree_Open);
actionProperties = new Action(Messages.get().PredefinedGraphTree_Properties) {
@Override
public void run() {
editPredefinedGraph();
}
};
actionShowFilter = new Action(Messages.get().PredefinedGraphTree_ShowFilter, Action.AS_CHECK_BOX) {
@Override
public void run() {
enableFilter(!initShowFilter);
actionShowFilter.setChecked(initShowFilter);
}
};
// $NON-NLS-1$
actionShowFilter.setId("org.netxms.ui.eclipse.perfview.actions.showFilter");
actionShowFilter.setChecked(initShowFilter);
// $NON-NLS-1$
actionShowFilter.setActionDefinitionId("org.netxms.ui.eclipse.perfview.commands.show_graph_filter");
final ActionHandler showFilterHandler = new ActionHandler(actionShowFilter);
handlerService.activateHandler(actionShowFilter.getActionDefinitionId(), showFilterHandler);
}
use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.
the class PredefinedGraphTree method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
parent.setLayout(new FormLayout());
// Create filter area
filterText = new FilterText(parent, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterText.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
}
});
viewer = new TreeViewer(parent, SWT.NONE);
viewer.setUseHashlookup(true);
viewer.setContentProvider(new GraphTreeContentProvider());
viewer.setLabelProvider(new GraphTreeLabelProvider());
viewer.setComparer(new IElementComparer() {
@Override
public int hashCode(Object element) {
if ((element instanceof GraphSettings)) {
return (int) ((GraphSettings) element).getId();
}
if ((element instanceof GraphFolder)) {
return ((GraphFolder) element).getName().hashCode();
}
return element.hashCode();
}
@Override
public boolean equals(Object a, Object b) {
if ((a instanceof GraphSettings) && (b instanceof GraphSettings))
return ((GraphSettings) a).getId() == ((GraphSettings) b).getId();
if ((a instanceof GraphFolder) && (b instanceof GraphFolder))
return ((GraphFolder) a).getName().equals(((GraphFolder) b).getName());
return a.equals(b);
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
actionOpen.run();
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@SuppressWarnings("rawtypes")
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Iterator it = selection.iterator();
boolean enabled = false;
while (it.hasNext()) {
if (it.next() instanceof GraphSettings) {
enabled = true;
break;
}
}
actionOpen.setEnabled(enabled);
actionDelete.setEnabled(enabled);
actionProperties.setEnabled(enabled);
}
});
filter = new GraphTreeFilter();
viewer.addFilter(filter);
// 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.getTree().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);
activateContext();
createActions();
contributeToActionBars();
createPopupMenu();
reloadGraphList();
session.addListener(this);
// Set initial focus to filter input line
if (initShowFilter)
filterText.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
}
use of org.netxms.client.datacollection.GraphSettings in project netxms by netxms.
the class TemplateGraphView method saveGraph.
/**
* Save this graph as predefined
*/
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten) {
SaveGraphDlg dlg = new SaveGraphDlg(getSite().getShell(), graphName, errorMessage, canBeOverwritten);
int result = dlg.open();
if (result == Window.CANCEL)
return;
final GraphSettings gs = new GraphSettings(0, session.getUserId(), 0, new ArrayList<AccessListElement>(0));
gs.setName(dlg.getName());
gs.setFlags(GraphSettings.GRAPH_FLAG_TEMPLATE);
if (result == SaveGraphDlg.OVERRIDE) {
new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.saveGraph(gs, canBeOverwritten);
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveSettingsError;
}
}.start();
} else {
new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
try {
session.saveGraph(gs, canBeOverwritten);
} catch (NXCException e) {
if (e.getErrorCode() == RCC.OBJECT_ALREADY_EXISTS) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExist, true);
}
});
} else {
if (e.getErrorCode() == RCC.ACCESS_DENIED) {
runInUIThread(new Runnable() {
@Override
public void run() {
saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false);
}
});
} else {
throw e;
}
}
}
}
@Override
protected String getErrorMessage() {
return Messages.get().HistoricalGraphView_SaveError;
}
}.start();
}
}
Aggregations