Search in sources :

Example 61 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog 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)

Example 62 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method doSave.

public void doSave(IProgressMonitor monitor) {
    final HashMap<String, List<String>> failedConfMap = new HashMap<String, List<String>>();
    if (editorInput.isEditCubridConf()) {
        editorInput.setCubridConfPropertyCount(cubridConfTabTableViewer.getTable().getColumnCount());
    }
    if (editorInput.isEditCMConf()) {
        editorInput.setCubridCMConfPropertyCount(cubridCMConfTabTableViewer.getTable().getColumnCount());
    }
    if (editorInput.isEditBrokerConf()) {
        editorInput.setBrokerConfPropertyCount(brokerConfTabTableViewer.getTable().getColumnCount());
    }
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getSite().getShell());
        progress.setCancelable(false);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.unifyHostConfigEditorSavingDataMsg, editorInput.getTaskCountValue());
                if (editorInput.isEditCubridConf()) {
                    LinkedHashMap<String, CubridConfConfig> cubridConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridConfConfig(cubridConfConfigListData, editorInput.getCubridConfPropertyCount());
                    List<String> failedcubridConfServer = unifyHostConfigUtil.saveCubridConf(monitor, cubridConfMap, editorInput.getCubridServers());
                    if (failedcubridConfServer.size() > 0) {
                        failedConfMap.put("cubrid.conf", failedcubridConfServer);
                    }
                }
                if (editorInput.isEditCMConf()) {
                    LinkedHashMap<String, CubridCMConfConfig> cubridCMConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridCMConfConfig(cubridConfCMConfigListData, editorInput.getCubridCMConfPropertyCount());
                    List<String> failedcubridConfServer = unifyHostConfigUtil.saveCubridCMConf(monitor, cubridCMConfMap, editorInput.getCubridServers());
                    if (failedcubridConfServer.size() > 0) {
                        failedConfMap.put("cm.conf", failedcubridConfServer);
                    }
                }
                if (editorInput.isEditBrokerConf()) {
                    LinkedHashMap<String, BrokerConfig> brokerConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridBrokerConfig(cubridBrokerConfListData, editorInput.getBrokerConfPropertyCount());
                    List<String> failedBrokerConfServer = unifyHostConfigUtil.saveBrokerConf(monitor, brokerConfMap, editorInput.getCubridServers());
                    if (failedBrokerConfServer.size() > 0) {
                        failedConfMap.put("cubrid_broker.conf", failedBrokerConfServer);
                    }
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    //		}
    if (failedConfMap.size() == 0) {
        CommonUITool.openInformationBox(Messages.unifyHostConfigEditorSavingDataSuccessMsg);
    } else {
        StringBuilder sb = new StringBuilder();
        for (Entry<String, List<String>> entry : failedConfMap.entrySet()) {
            sb.append(entry.getKey()).append(" on ").append(entry.getValue()).append(StringUtil.NEWLINE);
        }
        CommonUITool.openInformationBox(Messages.bind(Messages.unifyHostConfigEditorSavingErrMsg, sb.toString()));
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) List(java.util.List) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) LinkedHashMap(java.util.LinkedHashMap)

Example 63 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class CopyDatabaseDialog method execTask.

/**
	 * Execute tasks
	 * 
	 * @param buttonId the button id
	 * @param tasks the task array
	 * @param cancelable whether can be canceled
	 * @param shell the shell
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(getShell(), msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                if (!monitor.isCanceled()) {
                    display.syncExec(new Runnable() {

                        public void run() {
                            if (buttonId > 0) {
                                setReturnCode(buttonId);
                                close();
                            }
                        }
                    });
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 64 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class LoadMonitorStatisticDataProgress method loadMonitorStatisticData.

/**
	 * load MonitorStatisticData list
	 * 
	 * @return Catalog
	 */
public void loadMonitorStatisticData() {
    Display display = Display.getDefault();
    display.syncExec(new Runnable() {

        public void run() {
            try {
                new ProgressMonitorDialog(null).run(true, false, LoadMonitorStatisticDataProgress.this);
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    });
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display)

Example 65 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class KillTransactionDialog method executeKillTrans.

/**
	 * 
	 * Execute to kill transaction
	 * 
	 * @param buttonId the button id
	 * @param tasks the task array
	 * @param cancelable whether it can be cancelable
	 * @param shell the shell
	 */
public void executeKillTrans(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(getShell(), msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                if (!monitor.isCanceled()) {
                    display.syncExec(new Runnable() {

                        public void run() {
                            if (buttonId > 0) {
                                setReturnCode(buttonId);
                                close();
                            }
                        }
                    });
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)88 InvocationTargetException (java.lang.reflect.InvocationTargetException)81 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)74 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)74 ArrayList (java.util.ArrayList)27 Display (org.eclipse.swt.widgets.Display)22 CoreException (org.eclipse.core.runtime.CoreException)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 List (java.util.List)15 Shell (org.eclipse.swt.widgets.Shell)12 PartInitException (org.eclipse.ui.PartInitException)12 IFile (org.eclipse.core.resources.IFile)11 SQLException (java.sql.SQLException)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 SocketTask (com.cubrid.cubridmanager.core.common.socket.SocketTask)8 File (java.io.File)8 Item (org.talend.core.model.properties.Item)8 IProject (org.eclipse.core.resources.IProject)7 TableItem (org.eclipse.swt.widgets.TableItem)7