Search in sources :

Example 1 with MonitorStatisticPersistManager

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
    }
}
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)

Example 2 with MonitorStatisticPersistManager

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));
}
Also used : 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)

Example 3 with MonitorStatisticPersistManager

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;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) MonitorStatisticPersistManager(com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) List(java.util.List) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode)

Aggregations

ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)3 MonitorStatisticPersistManager (com.cubrid.cubridmanager.ui.spi.persist.MonitorStatisticPersistManager)3 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 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 List (java.util.List)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 IWorkbench (org.eclipse.ui.IWorkbench)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1