Search in sources :

Example 11 with MenuAdapter

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

the class MultiDatabaseLoginFailedDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    getShell().setText(Messages.multiDatabaseLoginDialogTitle);
    Composite parentComp = (Composite) super.createDialogArea(parent);
    setTitle(Messages.multiDatabaseLoginDialogTitle);
    setMessage(Messages.multiDatabaseLoginDialogMessages);
    databaseTable = new TableViewer(parentComp, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    databaseTable.getTable().setLayoutData(gridData);
    databaseTable.getTable().setHeaderVisible(true);
    databaseTable.getTable().setLinesVisible(true);
    final TableViewerColumn columnHost = new TableViewerColumn(databaseTable, SWT.CENTER);
    columnHost.getColumn().setWidth(120);
    columnHost.getColumn().setText(Messages.multiDatabaseLoginDialogColumnHostAddress);
    final TableViewerColumn columnDatabase = new TableViewerColumn(databaseTable, SWT.CENTER);
    columnDatabase.getColumn().setWidth(150);
    columnDatabase.getColumn().setText(Messages.multiDatabaseLoginDialogColumnDbName);
    final TableViewerColumn columnUser = new TableViewerColumn(databaseTable, SWT.CENTER);
    columnUser.getColumn().setWidth(100);
    columnUser.getColumn().setText(Messages.multiDatabaseLoginDialogColumnUser);
    final TableViewerColumn columnErrMsg = new TableViewerColumn(databaseTable, SWT.CENTER);
    columnErrMsg.getColumn().setWidth(200);
    columnErrMsg.getColumn().setText(Messages.multiDatabaseLoginDialogColumnErrMsg);
    final TableViewerColumn columnStatus = new TableViewerColumn(databaseTable, SWT.CENTER);
    columnStatus.getColumn().setWidth(100);
    columnStatus.getColumn().setText(Messages.multiDatabaseLoginDialogColumnStatus);
    databaseTable.setContentProvider(new ServerListContentProvider());
    databaseTable.setLabelProvider(new ServerListLabelProvider());
    databaseTable.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo = (MultiDatabaseloginFailedInfo) selection.getFirstElement();
            editHost(multiDatabaseloginFailedInfo);
            //if all database login , close this dialog
            if (checkAllDatabaseLogin()) {
                close();
            }
        }
    });
    databaseTable.setInput(failedDatabaseList);
    MenuManager menuManager = new MenuManager();
    Menu contextMenu = menuManager.createContextMenu(databaseTable.getTable());
    databaseTable.getTable().setMenu(contextMenu);
    Menu menu = new Menu(getShell(), SWT.POP_UP);
    final MenuItem itemEdit = new MenuItem(menu, SWT.PUSH);
    itemEdit.setText(Messages.multiDatabaseLoginDialogEditLabel);
    itemEdit.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            IStructuredSelection selection = (StructuredSelection) databaseTable.getSelection();
            MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo = (MultiDatabaseloginFailedInfo) selection.getFirstElement();
            editHost(multiDatabaseloginFailedInfo);
        }
    });
    menu.addMenuListener(new MenuAdapter() {

        public void menuShown(MenuEvent event) {
            IStructuredSelection selection = (IStructuredSelection) databaseTable.getSelection();
            MultiDatabaseloginFailedInfo multiDatabaseloginFailedInfo = (MultiDatabaseloginFailedInfo) selection.getFirstElement();
            if (multiDatabaseloginFailedInfo.getCubridDatabase().isLogined()) {
                itemEdit.setEnabled(false);
            } else {
                itemEdit.setEnabled(true);
            }
        }
    });
    databaseTable.getTable().setMenu(menu);
    databaseTable.getTable().addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (databaseTable.getTable().getSelectionIndices().length > 0) {
                getButton(EDIT_ID).setEnabled(true);
            } else {
                getButton(EDIT_ID).setEnabled(false);
            }
        }
    });
    return parentComp;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuAdapter(org.eclipse.swt.events.MenuAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) MenuManager(org.eclipse.jface.action.MenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

MenuAdapter (org.eclipse.swt.events.MenuAdapter)11 MenuEvent (org.eclipse.swt.events.MenuEvent)11 Menu (org.eclipse.swt.widgets.Menu)10 MenuItem (org.eclipse.swt.widgets.MenuItem)10 MenuManager (org.eclipse.jface.action.MenuManager)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 Point (org.eclipse.swt.graphics.Point)7 FocusEvent (org.eclipse.swt.events.FocusEvent)6 TableItem (org.eclipse.swt.widgets.TableItem)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 FocusAdapter (org.eclipse.swt.events.FocusAdapter)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 CubridBrokerConfEditAnnotationDialog (com.cubrid.common.ui.common.dialog.CubridBrokerConfEditAnnotationDialog)4 LinkedHashMap (java.util.LinkedHashMap)3 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)3 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3