Search in sources :

Example 1 with CubridBrokerConfEditAnnotationDialog

use of com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method registerCubridCMConfTableContextMenu.

/**
	 * register CubridCMConfTable context menu
	 */
private void registerCubridCMConfTableContextMenu() {
    cubridCMConfTabTableViewer.getTable().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(cubridCMConfTabTableViewer.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(cubridCMConfTabTableViewer.getTable());
    cubridCMConfTabTableViewer.getTable().setMenu(contextMenu);
    Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
    final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
    itemEditAnnotation.setText(Messages.confEditorTableMenuEditAnnotation);
    itemEditAnnotation.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("all")
        public void widgetSelected(SelectionEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked 
            Point pt = cubridCMConfTableClickPoint;
            int selectIndex = cubridCMConfTabTableViewer.getTable().getSelectionIndex();
            final TableItem item = cubridCMConfTabTableViewer.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0; i < cubridCMConfTabTableViewer.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        CommonUITool.openErrorBox(getSite().getShell(), Messages.annotationDialogOpenErrorMsg);
                        return;
                    }
                    IStructuredSelection selection = (IStructuredSelection) cubridCMConfTabTableViewer.getSelection();
                    HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
                    String serverName = cubridConfCMConfigListData.get(0).get(i + "");
                    String parentPropertyKey = valueMap.get("0");
                    String parentKey = " ";
                    Map<String, String> cubridMap = cubridConfCMConfigListData.get(1);
                    String cubridName = "";
                    if (cubridMap != null) {
                        cubridName = cubridMap.get(i + "");
                    }
                    if (selectIndex == 0) {
                        parentKey += serverName;
                    } else {
                        if (selectIndex == 1) {
                            parentKey += serverName + "->" + cubridName;
                        } else {
                            parentKey += serverName + "->" + cubridName + "->" + parentPropertyKey;
                        }
                    }
                    String annotationKey = Integer.toString(i) + BrokerConfPersistUtil.ANNOTATION;
                    CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(getSite().getShell(), parentKey, annotationKey, valueMap);
                    if (IDialogConstants.OK_ID == dialog.open()) {
                        setDirty(true);
                    }
                }
            }
        }
    });
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked 
            Point pt = cubridCMConfTableClickPoint;
            // click timing
            if (System.currentTimeMillis() - cubridCMConfTableClickPointTiming > 300) {
                itemEditAnnotation.setEnabled(false);
                return;
            }
            int selectIndex = cubridCMConfTabTableViewer.getTable().getSelectionIndex();
            if (selectIndex == -1) {
                itemEditAnnotation.setEnabled(false);
                return;
            }
            if (selectIndex == 0) {
                itemEditAnnotation.setEnabled(false);
                return;
            }
            final TableItem item = cubridCMConfTabTableViewer.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0; i < cubridCMConfTabTableViewer.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        itemEditAnnotation.setEnabled(false);
                    } else {
                        itemEditAnnotation.setEnabled(true);
                    }
                }
            }
        }
    });
    cubridCMConfTabTableViewer.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridBrokerConfEditAnnotationDialog(com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 2 with CubridBrokerConfEditAnnotationDialog

use of com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog in project cubrid-manager by CUBRID.

the class BrokerConfigEditComposite method registerContextMenu.

/**
	 * Register context menu
	 */
private void registerContextMenu() {
    final Table confTable = confTableViewer.getTable();
    confTable.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(confTable);
        }
    });
    final MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    final Menu contextMenu = menuManager.createContextMenu(confTable);
    confTable.setMenu(contextMenu);
    final Menu menu = new Menu(editorPart.getSite().getShell(), SWT.POP_UP);
    final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
    itemEditAnnotation.setText(Messages.cubridBrokerConfEditorTableMenuEditAnnotation);
    itemEditAnnotation.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("all")
        public void widgetSelected(SelectionEvent event) {
            // It seems like MenuEvent can't get the mouse click Point
            // so use the point which table MouseDown event marked
            final Point pt = clickPoint;
            int selectIndex = confTable.getSelectionIndex();
            if (selectIndex < 0) {
                return;
            }
            final TableItem item = confTable.getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0, len = confTable.getColumnCount(); i < len; i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        openErrorBox(editorPart.getSite().getShell(), Messages.cubridBrokerConfEditAnnotationDialogOpenErrorMsg);
                        return;
                    }
                    IStructuredSelection selection = (IStructuredSelection) confTableViewer.getSelection();
                    HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
                    String brokerName = confListData.get(0).get(String.valueOf(i));
                    String parentPropertyKey = valueMap.get("0");
                    String parentKey = " ";
                    if (selectIndex == 0) {
                        parentKey += brokerName;
                    } else {
                        parentKey += brokerName + "->" + parentPropertyKey;
                    }
                    String annotationKey = i + ANNOTATION;
                    CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(editorPart.getSite().getShell(), parentKey, annotationKey, valueMap);
                    if (dialog.open() == OK_ID) {
                        editorPart.setDirty(true);
                    }
                }
            }
        }
    });
    final MenuItem itemAddBrokerConf = new MenuItem(menu, SWT.PUSH);
    itemAddBrokerConf.setText(Messages.cubridBrokerConfEditorAddBrokerConfItemLabel);
    itemAddBrokerConf.setImage(CommonUIPlugin.getImage("icons/action/column_insert.png"));
    itemAddBrokerConf.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            addBrokerConfColumn();
            editorPart.setDirty(true);
        }
    });
    final MenuItem itemDeleteBrokerConf = new MenuItem(menu, SWT.PUSH);
    itemDeleteBrokerConf.setText(Messages.cubridBrokerConfEditorDeleteBrokerConfItemLabel);
    itemDeleteBrokerConf.setImage(CommonUIPlugin.getImage("icons/action/column_delete.png"));
    itemDeleteBrokerConf.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            // It seems like MenuEvent can't get the mouse click Point
            // so use the point which table MouseDown event marked
            final Point pt = clickPoint;
            final TableItem item = findSelectItem(confTable);
            if (item == null) {
                return;
            }
            int columnCount = confTable.getColumnCount();
            for (int i = 0; i < columnCount; i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    Map<String, String> valueMap = confListData.get(0);
                    String confName = valueMap.get(String.valueOf(i));
                    String msg = Messages.bind(Messages.cubridBrokerConfEditorDeleteBrokerConfConfirm, confName);
                    if (!CommonUITool.openConfirmBox(msg)) {
                        return;
                    }
                    confTable.getColumn(i).dispose();
                    for (int j = 1; j < columnCount; j++) {
                        confTable.getColumn(j).setText(Messages.cubridBrokerConfEditorBrokerTitle + (j - 1));
                    }
                    // delete data from cubridBrokerConfig, so regenerate cubridBrokerConfListData from cubridBrokerConfig
                    editorPart.getBrokerConfPersistUtil().deleteBrokerPropertyByBrokerName(brokerConfig, confName);
                    confListData.clear();
                    confListData.addAll(editorPart.parseBrokerConfigToCommonTableValue(brokerConfig));
                    confTableViewer.refresh();
                    editorPart.setDirty(true);
                    return;
                }
            }
        }
    });
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            // It seems like MenuEvent can't get the mouse click Point
            // so use the point which table MouseDown event marked
            final Point pt = clickPoint;
            // It will allow that the click timing is more than 300 msec.
            if (System.currentTimeMillis() - clickPointTiming > 300) {
                itemEditAnnotation.setEnabled(false);
                itemDeleteBrokerConf.setEnabled(false);
                itemAddBrokerConf.setEnabled(false);
                return;
            }
            int selectIndex = confTable.getSelectionIndex();
            if (selectIndex < 0) {
                itemEditAnnotation.setEnabled(false);
                itemDeleteBrokerConf.setEnabled(false);
                itemAddBrokerConf.setEnabled(true);
                return;
            }
            final TableItem item = confTable.getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0, len = confTable.getColumnCount(); i < len; i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    boolean enableToAccess = i > 0;
                    itemEditAnnotation.setEnabled(enableToAccess);
                    itemDeleteBrokerConf.setEnabled(enableToAccess);
                }
            }
            itemAddBrokerConf.setEnabled(true);
        }
    });
    confTable.setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Table(org.eclipse.swt.widgets.Table) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridBrokerConfEditAnnotationDialog(com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StringUtils.defaultString(org.apache.commons.lang.StringUtils.defaultString) FocusEvent(org.eclipse.swt.events.FocusEvent) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Map(java.util.Map) HashMap(java.util.HashMap) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 3 with CubridBrokerConfEditAnnotationDialog

use of com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method registerCubridBrokerTableContextMenu.

/**
	 * register CubridConfTable context menu
	 */
private void registerCubridBrokerTableContextMenu() {
    brokerConfTabTableViewer.getTable().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(brokerConfTabTableViewer.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(brokerConfTabTableViewer.getTable());
    brokerConfTabTableViewer.getTable().setMenu(contextMenu);
    Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
    final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
    itemEditAnnotation.setText(Messages.confEditorTableMenuEditAnnotation);
    itemEditAnnotation.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("all")
        public void widgetSelected(SelectionEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked 
            Point pt = cubridBrokerTableClickPoint;
            int selectIndex = brokerConfTabTableViewer.getTable().getSelectionIndex();
            final TableItem item = brokerConfTabTableViewer.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0; i < brokerConfTabTableViewer.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        CommonUITool.openErrorBox(getSite().getShell(), Messages.annotationDialogOpenErrorMsg);
                        return;
                    }
                    IStructuredSelection selection = (IStructuredSelection) brokerConfTabTableViewer.getSelection();
                    HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
                    String serverName = cubridBrokerConfListData.get(0).get(i + "");
                    String parentPropertyKey = valueMap.get("0");
                    String parentKey = " ";
                    Map<String, String> brokerMap = cubridBrokerConfListData.get(1);
                    String brokerName = "";
                    if (brokerMap != null) {
                        brokerName = brokerMap.get(i + "");
                    }
                    if (selectIndex == 0) {
                        parentKey += serverName;
                    } else {
                        if (selectIndex == 1) {
                            parentKey += serverName + "->" + brokerName;
                        } else {
                            parentKey += serverName + "->" + brokerName + "->" + parentPropertyKey;
                        }
                    }
                    String annotationKey = Integer.toString(i) + BrokerConfPersistUtil.ANNOTATION;
                    CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(getSite().getShell(), parentKey, annotationKey, valueMap);
                    if (IDialogConstants.OK_ID == dialog.open()) {
                        setDirty(true);
                    }
                }
            }
        }
    });
    final MenuItem itemAddBrokerConf = new MenuItem(menu, SWT.PUSH);
    itemAddBrokerConf.setText(com.cubrid.common.ui.common.Messages.cubridBrokerConfEditorAddBrokerConfItemLabel);
    itemAddBrokerConf.setImage(CommonUIPlugin.getImage("icons/action/column_insert.png"));
    itemAddBrokerConf.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            try {
                ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
                progress.setCancelable(true);
                progress.run(true, true, new IRunnableWithProgress() {

                    public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                //									int horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - 
                                //									brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                //									 = brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                monitor.beginTask(Messages.unifyHostConfigEditorAddColumnMsg, 1);
                                addBrokerConfColumn();
                                monitor.worked(1);
                            //									horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - horizontalSelectionInt;
                            //									brokerConfTabTableViewer.getTable().getHorizontalBar().setSelection(horizontalSelectionInt + 160);
                            }
                        });
                    }
                });
            } catch (Exception e) {
                LOGGER.error("", e);
            }
            setDirty(true);
        }
    });
    final MenuItem itemDeleteBrokerConf = new MenuItem(menu, SWT.PUSH);
    itemDeleteBrokerConf.setText(com.cubrid.common.ui.common.Messages.cubridBrokerConfEditorDeleteBrokerConfItemLabel);
    itemDeleteBrokerConf.setImage(CommonUIPlugin.getImage("icons/action/column_delete.png"));
    itemDeleteBrokerConf.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            try {
                ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
                progress.setCancelable(true);
                progress.run(true, true, new IRunnableWithProgress() {

                    public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                //									int horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - 
                                //									brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                //									 = brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                monitor.beginTask(Messages.unifyHostConfigEditorDelColumnMsg, 1);
                                delBrokerConfColumn();
                                monitor.worked(1);
                            //									horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - horizontalSelectionInt;
                            //									brokerConfTabTableViewer.getTable().getHorizontalBar().setSelection(horizontalSelectionInt + 160);
                            }
                        });
                    }
                });
            } catch (Exception e) {
                LOGGER.error("", e);
            }
            setDirty(true);
        }
    });
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked 
            Point pt = cubridBrokerTableClickPoint;
            // click timing
            if (System.currentTimeMillis() - cubridBrokerTableClickPointTiming > 300) {
                itemEditAnnotation.setEnabled(false);
                itemDeleteBrokerConf.setEnabled(false);
                itemAddBrokerConf.setEnabled(false);
                return;
            }
            int selectIndex = brokerConfTabTableViewer.getTable().getSelectionIndex();
            if (selectIndex == -1) {
                itemEditAnnotation.setEnabled(false);
                itemDeleteBrokerConf.setEnabled(false);
                itemAddBrokerConf.setEnabled(false);
                return;
            }
            if (selectIndex == 0) {
                itemEditAnnotation.setEnabled(false);
                itemDeleteBrokerConf.setEnabled(false);
                itemAddBrokerConf.setEnabled(true);
                return;
            }
            final TableItem item = brokerConfTabTableViewer.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0; i < brokerConfTabTableViewer.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        itemEditAnnotation.setEnabled(false);
                        itemDeleteBrokerConf.setEnabled(false);
                    } else {
                        itemEditAnnotation.setEnabled(true);
                        itemDeleteBrokerConf.setEnabled(true);
                    }
                }
            }
            itemAddBrokerConf.setEnabled(true);
        }
    });
    brokerConfTabTableViewer.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridBrokerConfEditAnnotationDialog(com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MenuEvent(org.eclipse.swt.events.MenuEvent)

Example 4 with CubridBrokerConfEditAnnotationDialog

use of com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method registerCubridConfTableContextMenu.

/**
	 * register CubridConfTable context menu
	 */
private void registerCubridConfTableContextMenu() {
    cubridConfTabTableViewer.getTable().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(cubridConfTabTableViewer.getTable());
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu contextMenu = menuManager.createContextMenu(cubridConfTabTableViewer.getTable());
    cubridConfTabTableViewer.getTable().setMenu(contextMenu);
    Menu menu = new Menu(this.getSite().getShell(), SWT.POP_UP);
    final MenuItem itemEditAnnotation = new MenuItem(menu, SWT.PUSH);
    itemEditAnnotation.setText(Messages.confEditorTableMenuEditAnnotation);
    itemEditAnnotation.addSelectionListener(new SelectionAdapter() {

        @SuppressWarnings("all")
        public void widgetSelected(SelectionEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked 
            Point pt = cubridConfTableClickPoint;
            int selectIndex = cubridConfTabTableViewer.getTable().getSelectionIndex();
            final TableItem item = cubridConfTabTableViewer.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0; i < cubridConfTabTableViewer.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        CommonUITool.openErrorBox(getSite().getShell(), Messages.annotationDialogOpenErrorMsg);
                        return;
                    }
                    IStructuredSelection selection = (IStructuredSelection) cubridConfTabTableViewer.getSelection();
                    HashMap<String, String> valueMap = (HashMap<String, String>) selection.getFirstElement();
                    String serverName = cubridConfConfigListData.get(0).get(i + "");
                    String parentPropertyKey = valueMap.get("0");
                    String parentKey = " ";
                    Map<String, String> cubridMap = cubridConfConfigListData.get(1);
                    String cubridName = "";
                    if (cubridMap != null) {
                        cubridName = cubridMap.get(i + "");
                    }
                    if (selectIndex == 0) {
                        parentKey += serverName;
                    } else {
                        if (selectIndex == 1) {
                            parentKey += serverName + "->" + cubridName;
                        } else {
                            parentKey += serverName + "->" + cubridName + "->" + parentPropertyKey;
                        }
                    }
                    String annotationKey = Integer.toString(i) + BrokerConfPersistUtil.ANNOTATION;
                    CubridBrokerConfEditAnnotationDialog dialog = new CubridBrokerConfEditAnnotationDialog(getSite().getShell(), parentKey, annotationKey, valueMap);
                    if (IDialogConstants.OK_ID == dialog.open()) {
                        setDirty(true);
                    }
                }
            }
        }
    });
    final MenuItem itemAddCubridConf = new MenuItem(menu, SWT.PUSH);
    itemAddCubridConf.setText(Messages.unifyHostConfigEditorAddCubridConfColumn);
    itemAddCubridConf.setImage(CommonUIPlugin.getImage("icons/action/column_insert.png"));
    itemAddCubridConf.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            try {
                ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
                progress.setCancelable(true);
                progress.run(true, true, new IRunnableWithProgress() {

                    public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                //									int horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - 
                                //									brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                //									 = brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                monitor.beginTask(Messages.unifyHostConfigEditorAddColumnMsg, 1);
                                addCubridConfColumn();
                                monitor.worked(1);
                            //									horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - horizontalSelectionInt;
                            //									brokerConfTabTableViewer.getTable().getHorizontalBar().setSelection(horizontalSelectionInt + 160);
                            }
                        });
                    }
                });
            } catch (Exception e) {
                LOGGER.error("", e);
            }
            setDirty(true);
        }
    });
    final MenuItem itemDelCubridConf = new MenuItem(menu, SWT.PUSH);
    itemDelCubridConf.setText(Messages.unifyHostConfigEditorDelCubridConfColumn);
    itemDelCubridConf.setImage(CommonUIPlugin.getImage("icons/action/column_delete.png"));
    itemDelCubridConf.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            try {
                ProgressMonitorDialog progress = new ProgressMonitorDialog(Display.getCurrent().getActiveShell());
                progress.setCancelable(true);
                progress.run(true, true, new IRunnableWithProgress() {

                    public void run(final IProgressMonitor monitor) throws InvocationTargetException {
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                //									int horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - 
                                //									brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                //									 = brokerConfTabTableViewer.getTable().getHorizontalBar().getSelection();
                                monitor.beginTask(Messages.unifyHostConfigEditorDelColumnMsg, 1);
                                delCubridConfColumn();
                                monitor.worked(1);
                            //									horizontalSelectionInt = brokerConfTabTableViewer.getTable().getHorizontalBar().getSize().y - horizontalSelectionInt;
                            //									brokerConfTabTableViewer.getTable().getHorizontalBar().setSelection(horizontalSelectionInt + 160);
                            }
                        });
                    }
                });
            } catch (Exception e) {
                LOGGER.error("", e);
            }
        }
    });
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            //seems like MenuEvent can't get the mouse click Point
            //so use the point which table MouseDown event marked 
            Point pt = cubridConfTableClickPoint;
            // click timing
            if (System.currentTimeMillis() - cubridConfTableClickPointTiming > 300) {
                itemEditAnnotation.setEnabled(false);
                itemDelCubridConf.setEnabled(false);
                itemAddCubridConf.setEnabled(false);
                return;
            }
            int selectIndex = cubridConfTabTableViewer.getTable().getSelectionIndex();
            if (selectIndex == -1) {
                itemEditAnnotation.setEnabled(false);
                itemDelCubridConf.setEnabled(false);
                itemAddCubridConf.setEnabled(false);
                return;
            }
            if (selectIndex == 0) {
                itemEditAnnotation.setEnabled(false);
                itemDelCubridConf.setEnabled(false);
                itemAddCubridConf.setEnabled(true);
                return;
            }
            final TableItem item = cubridConfTabTableViewer.getTable().getItem(selectIndex);
            if (item == null) {
                return;
            }
            for (int i = 0; i < cubridConfTabTableViewer.getTable().getColumnCount(); i++) {
                Rectangle rect = item.getBounds(i);
                if (rect.contains(pt)) {
                    if (i == 0) {
                        itemEditAnnotation.setEnabled(false);
                        itemDelCubridConf.setEnabled(false);
                    } else {
                        itemEditAnnotation.setEnabled(true);
                        itemDelCubridConf.setEnabled(true);
                    }
                }
            }
            itemAddCubridConf.setEnabled(true);
        }
    });
    cubridConfTabTableViewer.getTable().setMenu(menu);
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Rectangle(org.eclipse.swt.graphics.Rectangle) CubridBrokerConfEditAnnotationDialog(com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog) MenuAdapter(org.eclipse.swt.events.MenuAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusEvent(org.eclipse.swt.events.FocusEvent) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

CubridBrokerConfEditAnnotationDialog (com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 MenuManager (org.eclipse.jface.action.MenuManager)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 FocusAdapter (org.eclipse.swt.events.FocusAdapter)4 FocusEvent (org.eclipse.swt.events.FocusEvent)4 MenuAdapter (org.eclipse.swt.events.MenuAdapter)4 MenuEvent (org.eclipse.swt.events.MenuEvent)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Point (org.eclipse.swt.graphics.Point)4 Rectangle (org.eclipse.swt.graphics.Rectangle)4 Menu (org.eclipse.swt.widgets.Menu)4 MenuItem (org.eclipse.swt.widgets.MenuItem)4 TableItem (org.eclipse.swt.widgets.TableItem)4 LinkedHashMap (java.util.LinkedHashMap)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2