Search in sources :

Example 1 with AddStatisticPageDialog

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
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) MonitorStatisticPersistManager(com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) CubridNodeChangedEvent(com.cubrid.common.ui.spi.event.CubridNodeChangedEvent) IWorkbench(org.eclipse.ui.IWorkbench) AddStatisticPageDialog(com.cubrid.cubridmanager.ui.monstatistic.dialog.AddStatisticPageDialog) MonitorStatistic(com.cubrid.common.ui.spi.model.MonitorStatistic)

Aggregations

CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 MonitorStatistic (com.cubrid.common.ui.spi.model.MonitorStatistic)1 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 AddStatisticPageDialog (com.cubrid.cubridmanager.ui.monstatistic.dialog.AddStatisticPageDialog)1 MonitorStatisticPersistManager (com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1