use of com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager 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
}
}
use of com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager in project cubrid-manager by CUBRID.
the class DeleteMonitorStatisticPageAction 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 = (ICubridNode) obj[0];
String message = Messages.bind(Messages.confirmStatisticPageDeleteWarn, node.getId());
if (!CommonUITool.openConfirmBox(message)) {
return;
}
ICubridNode parent = node.getParent();
boolean isSingHost = parent != null && CubridNodeType.MONITOR_FOLDER.equals(parent.getType());
String hostId = null;
if (isSingHost) {
hostId = node.getServer().getServerName();
hostId = parent.getServer().getServerName();
}
MonitorStatisticPersistManager persistManager = MonitorStatisticPersistManager.getInstance();
persistManager.removeMonitorStatistic((MonitorStatistic) node, hostId);
persistManager.saveStatistic();
TreeViewer treeViewer = (TreeViewer) this.getSelectionProvider();
LayoutUtil.closeEditorAndView(node);
if (isSingHost) {
parent.removeChild(node);
treeViewer.remove(node);
} else {
/*TOOLS-3666 Refresh the input of TreeViewer*/
treeViewer.setInput(CubridMonitorNavigatorView.getTreeViewerInput());
}
CubridNodeManager.getInstance().fireCubridNodeChanged(new CubridNodeChangedEvent(node, CubridNodeChangedEventType.NODE_REMOVE));
}
use of com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager in project cubrid-manager by CUBRID.
the class AddStatisticPageDialog method createDialogArea.
/**
* Creates and returns the contents of the upper part of this dialog (above
* the button bar).
*
* @param parent The parent composite to contain the dialog area
* @return the dialog area control
*/
protected Control createDialogArea(Composite parent) {
Composite parentComp = (Composite) super.createDialogArea(parent);
Composite nameComp = new Composite(parentComp, SWT.RESIZE);
GridLayout layoutNameComp = new GridLayout(2, false);
nameComp.setLayout(layoutNameComp);
nameComp.setLayoutData(new GridData(GridData.FILL_BOTH));
Label lblName = new Label(nameComp, SWT.NONE);
final GridData gdLblName = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
gdLblName.widthHint = 80;
lblName.setLayoutData(gdLblName);
lblName.setText(Messages.lblPageName);
nameText = new Text(nameComp, SWT.BORDER);
final GridData gdNameText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gdNameText.widthHint = 220;
nameText.setLayoutData(gdNameText);
nameText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String name = nameText.getText().trim();
if (StringUtil.isEmpty(name)) {
isOkEnable[0] = false;
enableOk();
return;
} else {
isOkEnable[0] = true;
}
//check format
String regex = "^[0-9a-zA-Z_]{1,32}$";
if (!Pattern.matches(regex, name)) {
isOkEnable[0] = false;
enableOk();
return;
} else {
isOkEnable[0] = true;
}
//check duplicate name
MonitorStatisticPersistManager persistManager = MonitorStatisticPersistManager.getInstance();
String checkedId = name;
if (cubridServerId != null) {
checkedId += "@" + cubridServerId;
}
isOkEnable[1] = !persistManager.isContainedById(checkedId, cubridServerId);
/*TOOLS-3672 Avoid dashboard node and monitor statistic node have the same name*/
if (cubridServerId == null) {
List<ICubridNode> dashboardList = MonitorDashboardPersistManager.getInstance().getAllMonitorDashboards();
for (int i = 0; i < dashboardList.size(); i++) {
ICubridNode node = dashboardList.get(i);
if (name.equals(node.getLabel())) {
isOkEnable[1] = false;
}
}
}
enableOk();
}
});
return parentComp;
}
Aggregations