Search in sources :

Example 46 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.

the class CommonUITool method registerCopyPasteContextMenu.

/**
	 *
	 * Register context menu for styled text
	 *
	 * @param text StyledText
	 * @param isEditable boolean
	 */
public static void registerCopyPasteContextMenu(final StyledText text, final boolean isEditable, final boolean isCopiable) {
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (isCopiable) {
                IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
                if (copyAction instanceof CopyAction) {
                    manager.add(copyAction);
                    if (!copyAction.isEnabled()) {
                        FocusAction.changeActionStatus(copyAction, text);
                    }
                }
                IAction copyAllAction = ActionManager.getInstance().getAction(CopyAllAction.ID);
                if (copyAllAction instanceof CopyAllAction) {
                    manager.add(copyAllAction);
                    if (!copyAllAction.isEnabled()) {
                        FocusAction.changeActionStatus(copyAllAction, text);
                    }
                }
            }
            if (!isEditable) {
                return;
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction instanceof PasteAction) {
                manager.add(pasteAction);
                if (!pasteAction.isEnabled()) {
                    FocusAction.changeActionStatus(pasteAction, text);
                }
            }
        }
    });
    Menu contextMenu = menuManager.createContextMenu(text);
    text.setMenu(contextMenu);
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (!copyAction.isEnabled()) {
                FocusAction.changeActionStatus(copyAction, text);
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction != null && !pasteAction.isEnabled()) {
                FocusAction.changeActionStatus(pasteAction, text);
            }
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) IAction(org.eclipse.jface.action.IAction) CopyAction(com.cubrid.common.ui.query.action.CopyAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CopyAllAction(com.cubrid.common.ui.query.action.CopyAllAction) FocusEvent(org.eclipse.swt.events.FocusEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) PasteAction(com.cubrid.common.ui.query.action.PasteAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 47 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.

the class MonitorStatisticDetailViewPart method createInfoGroup.

private void createInfoGroup(Composite parent) {
    final int DEFAULT_WIDTH = 80;
    final Group infoGroup = new Group(parent, SWT.RESIZE);
    GridLayout infoGroupLayout = new GridLayout();
    infoGroupLayout.verticalSpacing = 10;
    infoGroup.setLayout(infoGroupLayout);
    final GridData gdInfoGroup = new GridData(SWT.FILL, SWT.CENTER, true, false);
    infoGroup.setLayoutData(gdInfoGroup);
    infoGroup.setText(Messages.msgGpChartInfo);
    Composite compInfo = new Composite(infoGroup, SWT.RESIZE);
    compInfo.setLayout(new FillLayout());
    compInfo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    hostTableViewer = new TableViewer(compInfo, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    hostTableViewer.getTable().setHeaderVisible(true);
    hostTableViewer.getTable().setLinesVisible(true);
    if (isMultiHost) {
        //Host Name
        final TableViewerColumn nameColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
        nameColumn.getColumn().setWidth(DEFAULT_WIDTH);
        nameColumn.getColumn().setText(Messages.lblHostName);
        //IP
        final TableViewerColumn ipColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
        ipColumn.getColumn().setWidth(DEFAULT_WIDTH + 20);
        ipColumn.getColumn().setText(Messages.lblIp);
        //Port
        final TableViewerColumn portColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
        portColumn.getColumn().setWidth(50);
        portColumn.getColumn().setText(Messages.lblPort);
    }
    //Data Type
    final TableViewerColumn dataTypeColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    dataTypeColumn.getColumn().setWidth(DEFAULT_WIDTH);
    dataTypeColumn.getColumn().setText(Messages.lblDataType);
    //Time Type
    final TableViewerColumn timeTypeColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    timeTypeColumn.getColumn().setWidth(DEFAULT_WIDTH);
    timeTypeColumn.getColumn().setText(Messages.lblTimeType);
    //Database Name
    final TableViewerColumn dbNameColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    dbNameColumn.getColumn().setWidth(DEFAULT_WIDTH + 20);
    dbNameColumn.getColumn().setText(Messages.lblDbName);
    //Database Volume Name
    final TableViewerColumn volNameColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    volNameColumn.getColumn().setWidth(DEFAULT_WIDTH + 40);
    volNameColumn.getColumn().setText(Messages.lblVolName);
    //Broker Name
    final TableViewerColumn brokerColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    brokerColumn.getColumn().setWidth(DEFAULT_WIDTH + 20);
    brokerColumn.getColumn().setText(Messages.lblBrokerName);
    //Metric
    final TableViewerColumn metricColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    metricColumn.getColumn().setWidth(DEFAULT_WIDTH * 2);
    metricColumn.getColumn().setText(Messages.lblMetric);
    //max value
    final TableViewerColumn maxColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    maxColumn.getColumn().setWidth(DEFAULT_WIDTH);
    maxColumn.getColumn().setText(Messages.msgMaxValue);
    //min value
    final TableViewerColumn minColumn = new TableViewerColumn(hostTableViewer, SWT.LEFT);
    minColumn.getColumn().setWidth(DEFAULT_WIDTH);
    minColumn.getColumn().setText(Messages.msgMinValue);
    hostTableViewer.setContentProvider(new HostTableViewerContentProvider());
    hostTableViewer.setLabelProvider(new HostTableViewerLabelProvider());
    hostTableViewer.getTable().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(hostTableViewer.getTable());
        }
    });
    if (statisticDataList != null) {
        hostTableViewer.setInput(statisticDataList);
        hostTableViewer.refresh();
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 48 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter in project cubrid-manager by CUBRID.

the class HostDialog method createDialogArea.

/**
	 * Create dialog area content
	 *
	 * @param parent the parent composite
	 * @return the control
	 */
protected Control createDialogArea(Composite parent) {
    Composite parentComp = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(parentComp, SWT.NONE);
    composite.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, -1));
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
    layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
    layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
    composite.setLayout(layout);
    Label hostNameLabel = new Label(composite, SWT.LEFT);
    hostNameLabel.setText(Messages.lblHostName);
    hostNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    hostNameText = new Text(composite, SWT.LEFT | SWT.BORDER);
    hostNameText.setTextLimit(ValidateUtil.MAX_NAME_LENGTH);
    if (server != null) {
        hostNameText.setText(server.getLabel());
    }
    hostNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    hostNameText.addModifyListener(this);
    Label addressNameLabel = new Label(composite, SWT.LEFT);
    addressNameLabel.setText(Messages.lblAddress);
    addressNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    addressText = new Text(composite, SWT.LEFT | SWT.BORDER);
    if (server != null) {
        addressText.setText(server.getHostAddress());
    } else {
        addressText.setText("localhost");
    }
    addressText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    addressText.addModifyListener(this);
    Label portNameLabel = new Label(composite, SWT.LEFT);
    portNameLabel.setText(Messages.lblPort);
    portNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    portText = new Text(composite, SWT.LEFT | SWT.BORDER);
    portText.setTextLimit(5);
    if (server != null) {
        portText.setText(server.getMonPort());
    } else {
        portText.setText("8001");
    }
    portText.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            portText.selectAll();
            portText.setFocus();
        }
    });
    portText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    portText.addModifyListener(this);
    Label userNameLabel = new Label(composite, SWT.LEFT);
    userNameLabel.setText(Messages.lblUserName);
    userNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    userNameText = new Text(composite, SWT.LEFT | SWT.BORDER);
    userNameText.setTextLimit(ValidateUtil.MAX_NAME_LENGTH);
    if (server != null) {
        userNameText.setText(server.getUserName());
    } else {
        userNameText.setText("admin");
    }
    userNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    userNameText.addModifyListener(this);
    Label passwordLabel = new Label(composite, SWT.LEFT);
    passwordLabel.setText(Messages.lblPassword);
    passwordLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    passwordText = new Text(composite, SWT.LEFT | SWT.PASSWORD | SWT.BORDER);
    passwordText.setTextLimit(ValidateUtil.MAX_NAME_LENGTH);
    passwordText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    if (server != null && server.getPassword() != null && server.isAutoSavePassword()) {
        passwordText.setText(server.getPassword());
    }
    passwordText.addModifyListener(this);
    new Label(composite, SWT.NONE);
    Label passHelp = new Label(composite, SWT.None);
    passHelp.setText(Messages.msgPasswordHelp);
    passHelp.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    new Label(composite, SWT.NONE).setLayoutData(CommonUITool.createGridData(1, 1, 0, 0));
    Composite btnComposite = new Composite(composite, SWT.NONE);
    btnComposite.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    layout = new GridLayout();
    layout.numColumns = 4;
    btnComposite.setLayout(layout);
    Button btnSavePassword = new Button(btnComposite, SWT.CHECK);
    btnSavePassword.setLayoutData(CommonUITool.createGridData(SWT.LEFT, 1, 1, -1, -1));
    btnSavePassword.setText(Messages.btnSavePassword);
    if (server == null) {
        btnSavePassword.setSelection(true);
        isSavePassword = true;
    } else {
        btnSavePassword.setSelection(server.isAutoSavePassword());
        isSavePassword = server.isAutoSavePassword();
    }
    btnSavePassword.addSelectionListener(new SelectionAdapter() {

        /**
			 * Sent when selection occurs in the control. The default behavior
			 * is to do nothing.
			 *
			 * @param e an event containing information about the selection
			 */
        public void widgetSelected(SelectionEvent event) {
            isSavePassword = !isSavePassword;
        }
    });
    btnAutoCommit = new Button(btnComposite, SWT.CHECK);
    btnAutoCommit.setLayoutData(CommonUITool.createGridData(SWT.LEFT, 1, 1, -1, -1));
    btnAutoCommit.setText(com.cubrid.common.ui.query.Messages.autoCommitLabel);
    boolean useAutoCommit = QueryOptions.getAutoCommit(server == null ? null : server.getServerInfo());
    btnAutoCommit.setSelection(useAutoCommit);
    btnUseTimeOut = new Button(btnComposite, SWT.CHECK);
    btnUseTimeOut.setLayoutData(CommonUITool.createGridData(SWT.LEFT, 1, 1, -1, -1));
    btnUseTimeOut.setText(Messages.btnSetTimeOut);
    btnUseTimeOut.setSelection(false);
    timeOutCombo = new Combo(btnComposite, SWT.READ_ONLY);
    timeOutCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    timeOutCombo.setItems(soTimeOutMsgs);
    timeOutCombo.setEnabled(false);
    btnUseTimeOut.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            timeOutCombo.setEnabled(btnUseTimeOut.getSelection());
            timeOutCombo.select(0);
        }
    });
    if (server != null && server.getServerInfo() != null) {
        int soTimeOut = server.getServerInfo().getSoTimeOut();
        if (soTimeOut != SocketTask.SOCKET_IO_TIMEOUT_MSEC) {
            int index = 0;
            for (int i = 0; i < soTimeOutValues.length; i++) {
                if (soTimeOutValues[i] == soTimeOut) {
                    index = i;
                    break;
                }
            }
            btnUseTimeOut.setSelection(true);
            timeOutCombo.setEnabled(true);
            timeOutCombo.select(index);
        }
    }
    Label jdbcLabel = new Label(composite, SWT.LEFT);
    jdbcLabel.setText(Messages.lblJdbcVersion);
    jdbcLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    jdbcVersionCombo = new Combo(composite, SWT.LEFT | SWT.READ_ONLY);
    jdbcVersionCombo.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    resetJdbcCombo();
    jdbcVersionCombo.addModifyListener(this);
    Button btnOpen = new Button(composite, SWT.NONE);
    {
        btnOpen.setText(Messages.btnBrowse);
        btnOpen.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
        btnOpen.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                JdbcManageDialog dialog = new JdbcManageDialog(getShell());
                if (IDialogConstants.OK_ID == dialog.open()) {
                    resetJdbcCombo();
                }
            }
        });
    }
    if (isNewHost && server != null) {
        hostNameText.selectAll();
        hostNameText.setFocus();
    } else if (server != null) {
        passwordText.selectAll();
        passwordText.setFocus();
    }
    if (isNewHost) {
        setTitle(Messages.titleAddHostDialog);
        setMessage(Messages.msgAddHostDialog);
    } else {
        if (actionIsConnect) {
            setTitle(Messages.titleConnectHostDialog);
            setMessage(Messages.msgConnectHostDialog);
        } else {
            setTitle(Messages.titleEditHostDialog);
            setMessage(Messages.msgEditHostDialog);
        }
    }
    if (actionIsConnect) {
        hostNameText.setEnabled(false);
        portText.setEnabled(false);
        passwordText.setEnabled(false);
        jdbcVersionCombo.setEnabled(false);
        userNameText.setEnabled(false);
        addressText.setEnabled(false);
        btnSavePassword.setEnabled(false);
        btnAutoCommit.setEnabled(false);
        btnUseTimeOut.setEnabled(false);
        timeOutCombo.setEnabled(false);
        btnOpen.setEnabled(false);
        passHelp.setVisible(false);
    }
    return parentComp;
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) JdbcManageDialog(com.cubrid.common.ui.common.dialog.JdbcManageDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 49 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter 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 50 with FocusAdapter

use of org.eclipse.swt.events.FocusAdapter 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

FocusAdapter (org.eclipse.swt.events.FocusAdapter)68 FocusEvent (org.eclipse.swt.events.FocusEvent)64 SelectionEvent (org.eclipse.swt.events.SelectionEvent)42 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)36 Composite (org.eclipse.swt.widgets.Composite)29 GridData (org.eclipse.swt.layout.GridData)28 Text (org.eclipse.swt.widgets.Text)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Label (org.eclipse.swt.widgets.Label)20 Button (org.eclipse.swt.widgets.Button)17 Menu (org.eclipse.swt.widgets.Menu)17 Point (org.eclipse.swt.graphics.Point)16 MenuManager (org.eclipse.jface.action.MenuManager)15 MenuItem (org.eclipse.swt.widgets.MenuItem)15 ModifyEvent (org.eclipse.swt.events.ModifyEvent)14 ModifyListener (org.eclipse.swt.events.ModifyListener)14 KeyEvent (org.eclipse.swt.events.KeyEvent)12 Combo (org.eclipse.swt.widgets.Combo)12 KeyAdapter (org.eclipse.swt.events.KeyAdapter)11 Group (org.eclipse.swt.widgets.Group)11