use of com.cubrid.cubridmanager.ui.monstatistic.dialog.AddStatisticPageDialog in project cubrid-manager by CUBRID.
the class AddMonitorStatisticPageAction method run.
/**
* Override the run method in order to open an instance of status monitor
* dialog
*
*/
public void run() {
Object[] obj = this.getSelectedObj();
ICubridNode node = null;
if (obj.length > 0) {
node = (ICubridNode) obj[0];
}
String hostId = null;
boolean isSingleHost = node != null && CubridNodeType.MONITOR_FOLDER.equals(node.getType());
if (isSingleHost) {
ServerInfo serverInfo = node.getServer().getServerInfo();
hostId = serverInfo.getServerName();
if (!serverInfo.isSupportMonitorStatistic()) {
CommonUITool.openWarningBox(Messages.needEnableMonitorStatisticMsg);
return;
}
}
AddStatisticPageDialog dialog = new AddStatisticPageDialog(getShell());
dialog.setCubridServerId(hostId);
if (dialog.open() == Dialog.OK) {
final String iconPath = "icons/navigator/status_item.png";
String labelName = dialog.getName();
String pageName = labelName;
if (hostId != null) {
pageName += "@" + hostId;
}
MonitorStatistic monitorStatisticNode = new MonitorStatistic(pageName, labelName, iconPath);
monitorStatisticNode.setType(CubridNodeType.MONITOR_STATISTIC_PAGE);
monitorStatisticNode.setEditorId(MonitorStatisticEditor.ID);
if (isSingleHost) {
monitorStatisticNode.setMultiHost(false);
ServerInfo serverInfo = node.getServer().getServerInfo();
monitorStatisticNode.setIp(serverInfo.getHostAddress());
monitorStatisticNode.setPort(serverInfo.getHostMonPort());
} else {
monitorStatisticNode.setMultiHost(true);
}
MonitorStatisticPersistManager persistManager = MonitorStatisticPersistManager.getInstance();
persistManager.addMonitorStatistic(monitorStatisticNode, hostId);
persistManager.saveStatistic();
//refresh TreeViewer
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
if (isSingleHost) {
node.addChild(monitorStatisticNode);
treeViewer.add(node, monitorStatisticNode);
} else {
/*TOOLS-3665 Refresh the input of TreeViewer*/
treeViewer.setInput(CubridMonitorNavigatorView.getTreeViewerInput());
}
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(monitorStatisticNode, CubridNodeChangedEventType.NODE_ADD));
try {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
workbenchWindow.getActivePage().openEditor(monitorStatisticNode, MonitorStatisticEditor.ID);
} catch (Exception ignore) {
}
} else {
//TODO
}
}
Aggregations