Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog setBlockOnOpen

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog setBlockOnOpen

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog setBlockOnOpen.

Prototype

public void setBlockOnOpen(boolean shouldBlock) 

Source Link

Document

Sets whether the open method should block until the window closes.

Usage

From source file:ch.hsr.ifs.cdt.metriculator.tagcloud.views.TagCloudViewPart.java

License:Open Source License

private void createSideTab(SashForm form) {
    Composite parent = new Composite(form, SWT.NONE);
    parent.setLayout(new GridLayout());
    parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    options = new CloudOptionsComposite(parent, SWT.NONE, viewer) {

        protected Group addLayoutButtons(Composite parent) {
            Group buttons = super.addLayoutButtons(parent);

            Label l = new Label(buttons, SWT.NONE);
            l.setText("Scale");
            final Combo scale = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            scale.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            scale.setItems(new String[] { "linear", "logarithmic" });
            scale.select(1);//from  w  ww  .ja v a  2 s  .  c  om
            scale.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    switch (scale.getSelectionIndex()) {
                    case 0:
                        labelProvider.setScale(TypeLabelProvider.Scaling.LINEAR);
                        break;
                    case 1:
                        labelProvider.setScale(TypeLabelProvider.Scaling.LOGARITHMIC);
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            l = new Label(buttons, SWT.NONE);
            l.setText("X Axis Variation");
            final Combo xAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            xAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            xAxis.setItems(new String[] { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" });
            xAxis.select(2);
            xAxis.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String item = xAxis.getItem(xAxis.getSelectionIndex());
                    layouter.setOption(DefaultLayouter.X_AXIS_VARIATION, Integer.parseInt(item));

                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });

            l = new Label(buttons, SWT.NONE);
            l.setText("Y Axis Variation");
            final Combo yAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            yAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            yAxis.setItems(new String[] { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" });
            yAxis.select(1);
            yAxis.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String item = yAxis.getItem(yAxis.getSelectionIndex());
                    layouter.setOption(DefaultLayouter.Y_AXIS_VARIATION, Integer.parseInt(item));
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });

            Button run = new Button(buttons, SWT.NONE);
            run.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            run.setText("Re-Position");
            run.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                            viewer.getControl().getShell());
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                    dialog.getProgressMonitor().beginTask("Layouting tag cloud...", 100);
                    viewer.reset(dialog.getProgressMonitor(), false);
                    dialog.close();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            Button layout = new Button(buttons, SWT.NONE);
            layout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            layout.setText("Re-Layout");
            layout.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(viewer.getControl().getShell());
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                    dialog.getProgressMonitor().beginTask("Layouting tag cloud...", 200);
                    viewer.setInput(viewer.getInput(), dialog.getProgressMonitor());
                    viewer.reset(dialog.getProgressMonitor(), false);
                    dialog.close();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            return buttons;
        };

    };
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    options.setLayoutData(gd);
}

From source file:com.google.gdt.eclipse.appsmarketplace.job.BackendJob.java

License:Open Source License

public static ProgressMonitorDialog launchBackendJob(BackendJob job, Shell shell) {
    ProgressMonitorDialog pdlg = new ProgressMonitorDialog(shell);
    job.setProgressDialog(pdlg);//from ww  w . ja  v  a2s.  c  o  m
    pdlg.open();
    pdlg.setCancelable(true);

    Thread thread = new Thread(job);
    thread.start();
    pdlg.setBlockOnOpen(true);
    return pdlg;
}

From source file:com.nokia.s60tools.compatibilityanalyser.ui.wizards.LibraryFilesPage.java

License:Open Source License

public void widgetSelected(SelectionEvent e) {
    if (e.widget == userDirs_radioBtn || e.widget == default_build_target_radioBtn) {
        removeDsoDir_Btn.setEnabled(userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn//from  www  . j  a  v  a2s. c om
                .setEnabled(userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);

        removeDllDir_Btn.setEnabled(userDirs_radioBtn.getSelection() && userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn
                .setEnabled(userDirs_radioBtn.getSelection() && userDllPath_list.getItemCount() != 0);

        GridData data = (GridData) buildTarget_list.getLayoutData();
        data.exclude = !buildtarget_radioBtn.getSelection();
        buildTarget_list.setVisible(buildtarget_radioBtn.getSelection());

        GridData data2 = (GridData) dllPaths_Folder.getLayoutData();
        data2.exclude = !userDirs_radioBtn.getSelection();
        dllPaths_Folder.setVisible(userDirs_radioBtn.getSelection());

        composite.getParent().setSize(composite.getParent().getSize().x + 1, composite.getParent().getSize().y);

        this.getContainer().updateButtons();
    } else if (e.widget == addDsoDir_Btn) {
        DirectoryDialog dirDialog = new DirectoryDialog(this.getShell());
        dirDialog.setFilterPath(releaseRoot);
        String newDir = dirDialog.open();
        if (newDir != null) {
            new TableItem(userDsoPath_list, SWT.NONE).setText(0, newDir);
            userDsoPath_list.select(0);
        }
        removeDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == addDllDir_Btn) {
        DirectoryDialog dirDialog = new DirectoryDialog(this.getShell());
        dirDialog.setFilterPath(releaseRoot);
        String newDir = dirDialog.open();
        if (newDir != null) {
            new TableItem(userDllPath_list, SWT.NONE).setText(0, newDir);
            userDllPath_list.select(0);
        }
        removeDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == buildTarget_list) {
        selectedPlatform = buildTarget_list.getSelection();
    }
    if (e.widget == analyseSelected_radioBtn) {
        dsoFiles_list.setEnabled(analyseSelected_radioBtn.getSelection());
        addDso_Btn.setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeDso_Btn
                .setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeAllDso_Btn
                .setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        removeNonExistingDso_Btn
                .setEnabled(analyseSelected_radioBtn.getSelection() && userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    }
    if (e.widget == addDso_Btn) {
        filesNamesList = new ArrayList<String>();
        displayFiles = new ArrayList<String>();
        children = new ArrayList<String>();
        subChildren = new ArrayList<String>();
        isMonitorCancelled = false;

        if (userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() == 1) {
            absolutePath = userDsoPath_list.getItem(0).getText(0);
            absolutePath = FileMethods.convertForwardToBackwardSlashes(absolutePath);

            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this,
                    absolutePath, false);

            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        monitor.beginTask("Getting files from " + absolutePath, 10);
                        getFiles(absolutePath, monitor);
                        monitor.worked(5);
                        getFilesFromSubDirs(absolutePath, monitor);
                        monitor.done();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };
            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }

        } else if (userDirs_radioBtn.getSelection() && userDsoPath_list.getItemCount() > 1) {
            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this, "",
                    false);

            String[] paths = new String[userDsoPath_list.getItems().length];
            for (int i = 0; i < userDsoPath_list.getItems().length; i++)
                paths[i] = userDsoPath_list.getItem(i).getText(0);
            allLibsPaths = paths;

            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        int i = 1;
                        for (String path : allLibsPaths) {
                            absolutePath = FileMethods.convertForwardToBackwardSlashes(path);
                            monitor.beginTask("Getting files from " + absolutePath, allLibsPaths.length);
                            getFiles(absolutePath, monitor);
                            getFilesFromSubDirs(absolutePath, monitor);
                            monitor.worked(i++);
                        }
                        monitor.done();

                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };

            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }
        } else if (buildtarget_radioBtn.getSelection()) {
            if (releaseRoot != null) {
                addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this,
                        "", false);
                String[] paths = new String[buildTarget_list.getSelectionCount()];

                for (int i = 0; i < buildTarget_list.getSelectionCount(); i++) {
                    paths[i] = FileMethods.appendPathSeparator(releaseRoot) + buildTarget_list.getSelection()[i]
                            + File.separator + Messages.getString("LibraryFilesPage.lib"); //$NON-NLS-1$ //$NON-NLS-2$;
                }

                allLibsPaths = paths;

                IRunnableWithProgress op = new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor) {
                        try {
                            int i = 1;
                            for (String path : allLibsPaths) {
                                absolutePath = FileMethods.convertForwardToBackwardSlashes(path);
                                monitor.beginTask("Getting files from " + absolutePath, allLibsPaths.length);
                                getFiles(absolutePath, monitor);
                                getFilesFromSubDirs(absolutePath, monitor);
                                monitor.worked(i++);
                            }
                            monitor.done();

                        } catch (Exception e1) {
                            e1.printStackTrace();
                        }
                    }
                };

                try {
                    IWorkbench wb = PlatformUI.getWorkbench();
                    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                    Shell shell = win != null ? win.getShell() : null;
                    ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                    progDlg.run(true, true, op);
                    progDlg.setBlockOnOpen(true);
                } catch (InvocationTargetException err) {
                    err.printStackTrace();
                } catch (InterruptedException err) {
                    err.printStackTrace();
                }
            }

        } else if (default_build_target_radioBtn.getSelection()) {
            String buildTarget = CompatibilityAnalyserEngine.getDefaultBuildPlatform(releaseRoot,
                    currentSdk.productSdkVersion);

            absolutePath = FileMethods.appendPathSeparator(releaseRoot) + buildTarget + File.separator
                    + Messages.getString("LibraryFilesPage.lib"); //$NON-NLS-1$ //$NON-NLS-2$
            absolutePath = FileMethods.convertForwardToBackwardSlashes(absolutePath);
            addDialog = new ShowFilesListDialog(Display.getCurrent().getActiveShell(), dsoFiles_list, this,
                    absolutePath, false);

            IRunnableWithProgress op = new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor) {
                    try {
                        monitor.beginTask("Getting files from " + absolutePath, 10);
                        getFiles(absolutePath, monitor);
                        monitor.worked(5);
                        getFilesFromSubDirs(absolutePath, monitor);
                        monitor.done();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }
                }
            };
            try {
                IWorkbench wb = PlatformUI.getWorkbench();
                IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
                Shell shell = win != null ? win.getShell() : null;
                ProgressMonitorDialog progDlg = new ProgressMonitorDialog(shell);
                progDlg.run(true, true, op);
                progDlg.setBlockOnOpen(true);
            } catch (InvocationTargetException err) {
                err.printStackTrace();
            } catch (InterruptedException err) {
                err.printStackTrace();
            }

        }

        if (!isMonitorCancelled) {
            if (filesNamesList.size() != dsoFiles_list.getItemCount())
                for (String name : filesNamesList) {
                    if (!isPreviouslySelected(name))
                        displayFiles.add(name);
                    else {
                        if (subChildren.contains(name))
                            subChildren.remove(name);
                        if (children.contains(name))
                            children.remove(name);
                    }
                }
            Collections.sort(displayFiles);
            addDialog.children = children;
            addDialog.subChildren = subChildren;

            if (displayFiles.size() == 0 && filesNamesList.size() != 0) {
                Runnable showMessageRunnable = new Runnable() {
                    public void run() {
                        MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                                Messages.getString("HeaderFilesPage.CompatibilityAnalyser"), //$NON-NLS-1$
                                "All libraries in the root directory are already selected"); //$NON-NLS-1$
                    }
                };
                Display.getDefault().asyncExec(showMessageRunnable);
            } else if (filesNamesList.size() == 0) {
                Runnable showMessageRunnable = new Runnable() {
                    public void run() {
                        MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                                Messages.getString("HeaderFilesPage.CompatibilityAnalyser"), //$NON-NLS-1$
                                "No libraries exist under the given directory path"); //$NON-NLS-1$
                    }
                };
                Display.getDefault().asyncExec(showMessageRunnable);
            } else {
                addDialog.open();
                addDialog.filesList.setItems(displayFiles.toArray(new String[displayFiles.size()]));
                addDialog.filesList.select(0);
                addDialog.fileNamesList = addDialog.filesList.getItems();
            }

        }
        this.getContainer().updateButtons();
    } else if (e.widget == removeDso_Btn) {
        dsoFiles_list.remove(dsoFiles_list.getSelectionIndices());
        dsoFiles_list.select(0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeAllDso_Btn) {
        dsoFiles_list.removeAll();
        this.getContainer().updateButtons();
    } else if (e.widget == removeNonExistingDso_Btn) {
        int[] invalidIndices = new int[invalidLibsCount];
        int j = 0;

        for (int i = 0; i < dsoFiles_list.getItemCount(); i++) {
            System.out.println("Item Color is " + dsoFiles_list.getItem(i).getForeground()
                    + " And InvalidColor is " + invalidColor);
            if (dsoFiles_list.getItem(i).getForeground().equals(invalidColor)) {
                invalidIndices[j] = i;
                j++;
            }
        }
        dsoFiles_list.remove(invalidIndices);
        invalidLibsCount = 0;

        this.getContainer().updateButtons();
    } else if (e.widget == removeDsoDir_Btn) {
        userDsoPath_list.remove(userDsoPath_list.getSelectionIndices());
        userDsoPath_list.select(0);
        removeDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeAllDsoDir_Btn) {
        userDsoPath_list.removeAll();
        removeDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        removeAllDsoDir_Btn.setEnabled(userDsoPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeDllDir_Btn) {
        userDllPath_list.remove(userDllPath_list.getSelectionIndices());
        userDllPath_list.select(0);
        removeDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    } else if (e.widget == removeAllDllDir_Btn) {
        userDllPath_list.removeAll();
        removeDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        removeAllDllDir_Btn.setEnabled(userDllPath_list.getItemCount() != 0);
        this.getContainer().updateButtons();
    }
}

From source file:com.salesforce.ide.schemabrowser.ui.SchemaBrowser.java

License:Open Source License

private void createTree(Composite composite) {
    imageNotChecked = ForceImages.get(ForceImages.IMAGE_NOT_CHECKED);
    imageChecked = ForceImages.get(ForceImages.IMAGE_CHECKED);
    imageArrowDown = ForceImages.get(ForceImages.IMAGE_ARROW_DOWN);
    imageArrowUp = ForceImages.get(ForceImages.IMAGE_ARROW_UP);
    imageBlank = ForceImages.get(ForceImages.IMAGE_BLANK);

    final Composite thisComposite = composite;

    provider = new SchemaTreeLabelProvider();

    Tree tree = this.schemaEditorComposite.getTree();
    tree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            if (event.item instanceof TreeItem) {
                selectedItem = (TreeItem) event.item;
            } else {
                selectedItem = null;//from  w  w  w  . j a  v  a 2  s. c  o  m
            }
        }

    });
    tree.addTreeListener(new org.eclipse.swt.events.TreeListener() {
        public void treeExpanded(org.eclipse.swt.events.TreeEvent e) {
            final TreeItem selectedItem = (TreeItem) e.item;
            Boolean isTopLevel = (Boolean) selectedItem.getData(IS_TOP_LEVEL);
            if ((isTopLevel != null) && isTopLevel.booleanValue()) {
                if (selectedItem.getItemCount() == 1) {
                    Runnable lt = new Runnable() {
                        public void run() {
                            ProgressMonitorDialog mon = new ProgressMonitorDialog(getShell());
                            mon.getProgressMonitor();
                            mon.setBlockOnOpen(false);
                            mon.open();
                            loadTreeData(selectedItem, thisComposite, mon.getProgressMonitor());
                            setHasCheckableChildren(selectedItem, Boolean.TRUE);
                            setIsTopLevel(selectedItem, Boolean.TRUE);
                            setItemNotChecked(selectedItem);
                            selectedItem.setImage(
                                    provider.getImage(0, selectedItem.getText(), selectedItem.getParent()));
                            mon.close();
                        }
                    };
                    Runnable lb = new Runnable() {
                        public void run() {
                            ProgressMonitorDialog mon = new ProgressMonitorDialog(getShell());
                            mon.getProgressMonitor();
                            mon.setBlockOnOpen(false);
                            mon.open();
                            mon.getProgressMonitor().beginTask("Get object definition...", 2);
                            loadObject(selectedItem.getText(), mon.getProgressMonitor());
                            mon.close();
                        }
                    };

                    getSite().getShell().getDisplay().asyncExec(lb);
                    getSite().getShell().getDisplay().asyncExec(lt);
                }
            } else {
                Integer type = (Integer) selectedItem.getData(TYPE);
                if (type != null) {
                    if (type.equals(SchemaBrowser.CHILD_RELATIONSHIP_NODE)
                            && selectedItem.getData(LOADED).equals(Boolean.FALSE)) {
                        Runnable getThisChildSchema = new Runnable() {
                            public void run() {
                                ProgressMonitorDialog mon = new ProgressMonitorDialog(getShell());
                                mon.getProgressMonitor();
                                mon.setBlockOnOpen(false);
                                mon.open();
                                mon.getProgressMonitor().beginTask(MESSAGE_GETTING_CHILD, 2);
                                loadOneChildRelationship(selectedItem, mon.getProgressMonitor());
                                mon.close();
                            }
                        };

                        getSite().getShell().getDisplay().asyncExec(getThisChildSchema);

                    } else if (SchemaBrowser.LOOKUP_RELATIONSHIP_NODE.equals(type)
                            && Boolean.FALSE.equals(selectedItem.getData(LOADED))) {
                        Runnable getThisChildSchema = new Runnable() {
                            public void run() {
                                ProgressMonitorDialog mon = new ProgressMonitorDialog(getShell());
                                mon.getProgressMonitor();
                                mon.setBlockOnOpen(false);
                                mon.open();
                                mon.getProgressMonitor().beginTask(MESSAGE_GETTING_LOOKUP, 2);
                                loadOneChildRelationship(selectedItem, mon.getProgressMonitor());
                                mon.close();
                            }
                        };

                        getSite().getShell().getDisplay().asyncExec(getThisChildSchema);
                    }
                }

            }
            wasExpanded = true;
        }

        public void treeCollapsed(org.eclipse.swt.events.TreeEvent e) {
            wasExpanded = true;
        }
    });

    tree.addMouseListener(new org.eclipse.swt.events.MouseListener() {
        public void mouseUp(org.eclipse.swt.events.MouseEvent e) {
            if (!wasExpanded) {
                if (selectedItem != null) {
                    if (selectedItem.getImage() != null) {
                        Rectangle rect = selectedItem.getBounds();
                        Image img = selectedItem.getImage();
                        Rectangle imgRect = img.getBounds();
                        int leftMost = rect.x - imgRect.width - 3;
                        int rightMost = rect.x - 3;
                        if ((e.x >= leftMost) && (e.x <= rightMost)) {
                            Integer imageType = (Integer) selectedItem.getData(IMAGE_TYPE);
                            if (imageType != null) {
                                if (imageType.intValue() == IMAGE_TYPE_CHECKED) {
                                    setItemChecked(selectedItem);
                                } else {
                                    setItemNotChecked(selectedItem);
                                }

                                Integer type = (Integer) selectedItem.getData(TYPE);
                                if (SchemaBrowser.CHILD_RELATIONSHIP_NODE.equals(type)
                                        && Boolean.FALSE.equals(selectedItem.getData(LOADED))) {
                                    if ((selectedItem.getData(LOADED) != null)
                                            && Boolean.FALSE.equals(selectedItem.getData(LOADED))) {
                                        Runnable getThisChildSchema = new Runnable() {
                                            public void run() {
                                                ProgressMonitorDialog mon = new ProgressMonitorDialog(
                                                        getShell());
                                                mon.getProgressMonitor();
                                                mon.setBlockOnOpen(false);
                                                mon.open();
                                                mon.getProgressMonitor().beginTask(MESSAGE_GETTING_CHILD, 2);
                                                loadOneChildRelationship(selectedItem,
                                                        mon.getProgressMonitor());
                                                mon.close();
                                            }
                                        };

                                        getSite().getShell().getDisplay().syncExec(getThisChildSchema);

                                    }
                                } else if (SchemaBrowser.LOOKUP_RELATIONSHIP_NODE.equals(type)
                                        && Boolean.FALSE.equals(selectedItem.getData(LOADED))) {
                                    Runnable getThisChildSchema = new Runnable() {
                                        public void run() {
                                            ProgressMonitorDialog mon = new ProgressMonitorDialog(getShell());
                                            mon.getProgressMonitor();
                                            mon.setBlockOnOpen(false);
                                            mon.open();
                                            mon.getProgressMonitor().beginTask(MESSAGE_GETTING_LOOKUP, 2);
                                            loadOneChildRelationship(selectedItem, mon.getProgressMonitor());
                                            mon.close();
                                        }
                                    };

                                    getSite().getShell().getDisplay().asyncExec(getThisChildSchema);
                                }

                                setChildren(selectedItem,
                                        ((Integer) selectedItem.getData(IMAGE_TYPE)).intValue());

                                while (selectedItem.getParentItem() != null) {
                                    TreeItem parent = selectedItem.getParentItem();
                                    boolean setParent = true;
                                    for (int i = 0; i < parent.getItemCount(); i++) {
                                        if (!parent.getItem(i).equals(selectedItem)
                                                && parent.getItem(i).getImage().equals(imageChecked)) {
                                            setParent = false;
                                            break;
                                        }
                                    }

                                    if (!setParent) {
                                        break;
                                    }
                                    if (imageType.intValue() == 0) {
                                        setItemChecked(parent);
                                    } else {
                                        setItemNotChecked(parent);
                                    }
                                    selectedItem = parent;
                                }
                                fireSelectionChanged(selectedItem);
                            }
                        }
                    }
                }
            }
            wasExpanded = false;
        }

        public void mouseDoubleClick(org.eclipse.swt.events.MouseEvent e) {
        }

        public void mouseDown(org.eclipse.swt.events.MouseEvent e) {
        }
    });
    initialize();
}

From source file:net.openchrom.chromatogram.msd.process.supplier.jython.ui.Activator.java

License:Open Source License

@SuppressWarnings("unused")
private ObtainInterpreterInfoOperation tryInterpreter(Tuple<String, String> interpreterNameAndExecutable,
        IInterpreterManager interpreterManager, boolean autoSelectFolders, boolean displayErrors,
        PrintWriter logger, Shell shell) throws Exception {

    String executable = interpreterNameAndExecutable.o2;
    logger.println("- Ok, file is non-null. Getting info on:" + executable);
    ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(shell);
    monitorDialog.setBlockOnOpen(false);
    ObtainInterpreterInfoOperation operation;
    while (true) {
        operation = new ObtainInterpreterInfoOperation(interpreterNameAndExecutable.o2, logger,
                interpreterManager, autoSelectFolders);
        monitorDialog.run(true, false, operation);
        if (operation.e != null) {
            logger.println("- Some error happened while getting info on the interpreter:");
            operation.e.printStackTrace(logger);
            String errorTitle = "Unable to get info on the interpreter: " + executable;
            if (operation.e instanceof SimpleJythonRunner.JavaNotConfiguredException) {
                SimpleJythonRunner.JavaNotConfiguredException javaNotConfiguredException = (SimpleJythonRunner.JavaNotConfiguredException) operation.e;
                if (displayErrors) {
                    ErrorDialog.openError(shell, errorTitle, javaNotConfiguredException.getMessage(),
                            PydevPlugin.makeStatus(IStatus.ERROR, "Java vm not configured.\n",
                                    javaNotConfiguredException));
                }//from w ww  .  j av a2s . c  o m
                throw new Exception(javaNotConfiguredException);
            } else if (operation.e instanceof JDTNotAvailableException) {
                JDTNotAvailableException noJdtException = (JDTNotAvailableException) operation.e;
                if (displayErrors) {
                    ErrorDialog.openError(shell, errorTitle, noJdtException.getMessage(),
                            PydevPlugin.makeStatus(IStatus.ERROR, "JDT not available.\n", noJdtException));
                }
                throw new Exception(noJdtException);
            } else {
                if (displayErrors) {
                    // show the user a message (so that it does not fail silently)...
                    String errorMsg = "Unable to get info on the interpreter: " + executable + "\n\n"
                            + "Common reasons include:\n\n" + "- Using an unsupported version\n"
                            + "  (Python and Jython require at least version 2.1 and IronPython 2.6).\n" + "\n"
                            + "- Specifying an invalid interpreter\n"
                            + "  (usually a link to the actual interpreter on Mac or Linux)" + "";
                    ErrorDialog.openError(shell, errorTitle, errorMsg,
                            PydevPlugin.makeStatus(IStatus.ERROR, "See error log for details.", operation.e));
                }
                throw new Exception(operation.e);
            }
        } else if (operation.result == null) {
            // Folder selection was canceled, exit
            return null;
        }
        // Ok, we got the result, so, let's check if things are correct (i.e.: do we have threading.py, traceback.py?)
        HashSet<String> hashSet = new HashSet<String>();
        hashSet.add("threading");
        hashSet.add("traceback");
        String[] validSourceFiles = FileTypesPreferencesPage.getValidSourceFiles();
        Set<String> extensions = new HashSet<String>(Arrays.asList(validSourceFiles));
        for (String s : operation.result.libs) {
            File file = new File(s);
            if (file.isDirectory()) {
                String[] directoryFiles = file.list();
                if (directoryFiles != null) {
                    for (String found : directoryFiles) {
                        List<String> split = StringUtils.split(found, '.');
                        if (split.size() == 2) {
                            if (extensions.contains(split.get(1))) {
                                hashSet.remove(split.get(0));
                            }
                        }
                    }
                } else {
                    logger.append("Warning: unable to get contents of directory: " + file
                            + " (permission not available, it's not a dir or dir does not exist).");
                }
            } else if (file.isFile()) {
                // Zip file?
                try {
                    try (ZipFile zipFile = new ZipFile(file)) {
                        for (String extension : validSourceFiles) {
                            if (zipFile.getEntry("threading." + extension) != null) {
                                hashSet.remove("threading");
                            }
                            if (zipFile.getEntry("traceback." + extension) != null) {
                                hashSet.remove("traceback");
                            }
                        }
                    }
                } catch (Exception e) {
                    // ignore (not zip file)
                }
            }
        }
        if (hashSet.size() > 0) {
            if (displayErrors) {
                // The /Lib folder wasn't there (or at least threading.py and traceback.py weren't found)
                int choice = PyDialogHelpers.openCriticalWithChoices(
                        "Error: Python stdlib source files not found.",
                        "Error: Python stdlib not found or stdlib found without .py files.\n" + "\n"
                                + "It seems that the Python /Lib folder (which contains the standard library) "
                                + "was not found/selected during the install process or the stdlib does not contain "
                                + "the required .py files (i.e.: only has .pyc files).\n" + "\n"
                                + "This folder (which contains files such as threading.py and traceback.py) is "
                                + "required for PyDev to function properly, and it must contain the actual source files, not "
                                + "only .pyc files. if you don't have the .py files in your install, please use an install from "
                                + "python.org or grab the standard library for your install from there.\n"
                                + "\n"
                                + "If this is a virtualenv install, the /Lib folder from the base install needs to be selected "
                                + "(unlike the site-packages which is optional).\n" + "\n"
                                + "What do you want to do?\n\n"
                                + "Note: if you choose to proceed, the /Lib with the standard library .py source files must "
                                + "be added later on, otherwise PyDev may not function properly.",
                        new String[] { "Re-select folders", "Cancel", "Proceed anyways" });
                if (choice == 0) {
                    // Keep on with outer while(true)
                    continue;
                }
                if (choice == 1) {
                    // Return nothing and exit quietly on a cancel
                    return null;
                }
            } else {
                // Don't allow auto-selection of an interpreter missing these folders
                logger.println("- Could not find /Lib folder, exiting with error.");
                throw new Exception(ERMSG_NOLIBS + executable);
            }
        }
        operation.result.setName(interpreterNameAndExecutable.o1);
        logger.println("- Success getting the info. Result:" + operation.result);
        return operation;
    }
}

From source file:org.eclipse.gef4.cloudio.examples.application.actions.LoadFileAction.java

License:Open Source License

@Override
public void run(IAction action) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);

    dialog.setText("Select text file...");
    String sourceFile = dialog.open();
    if (sourceFile == null)
        return;//w  w  w  .  j  ava2s .  c om
    ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
    try {
        List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8");
        pd.setBlockOnOpen(false);
        pd.open();
        pd.getProgressMonitor().beginTask("Generating cloud...", 200);
        TagCloudViewer viewer = getViewer();
        viewer.setInput(types, pd.getProgressMonitor());
        //viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        pd.close();
    }
}

From source file:org.eclipse.gef4.cloudio.examples.application.ui.TagCloudViewPart.java

License:Open Source License

private void createSideTab(SashForm form) {
    Composite parent = new Composite(form, SWT.NONE);
    parent.setLayout(new GridLayout());
    parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    options = new CloudOptionsComposite(parent, SWT.NONE, viewer) {

        protected Group addMaskButton(Composite parent) {
            Group buttons = new Group(parent, SWT.SHADOW_IN);
            buttons.setLayout(new GridLayout(2, true));
            buttons.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            Label l = new Label(buttons, SWT.NONE);
            l.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            l.setText("Mask");
            Button file = new Button(buttons, SWT.FLAT);
            file.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
            file.setText("Open...");
            file.addListener(SWT.Selection, new Listener() {

                @Override//from   w  w w .  ja v a 2 s .co  m
                public void handleEvent(Event event) {
                    FileDialog fd = new FileDialog(getShell(), SWT.OPEN);

                    fd.setText("Select a square b&w png image as mask...");
                    String sourceFile = fd.open();
                    if (sourceFile == null)
                        return;
                    try {
                        ImageLoader loader = new ImageLoader();
                        BufferedInputStream in = new BufferedInputStream(
                                new FileInputStream(new File(sourceFile)));
                        ImageData[] data = loader.load(in);
                        in.close();
                        viewer.getCloud().setBackgroundMask(data[0]);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            });
            return buttons;
        }

        protected void addGroups() {
            addMaskButton(this);
            super.addGroups();
        }

        protected Group addLayoutButtons(Composite parent) {
            Group buttons = super.addLayoutButtons(parent);

            Label l = new Label(buttons, SWT.NONE);
            l.setText("Scale");
            final Combo scale = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            scale.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            scale.setItems(new String[] { "linear", "logarithmic" });
            scale.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    switch (scale.getSelectionIndex()) {
                    case 0:
                        labelProvider.setScale(TypeLabelProvider.Scaling.LINEAR);
                        break;
                    case 1:
                        labelProvider.setScale(TypeLabelProvider.Scaling.LOGARITHMIC);
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            scale.select(1);
            l = new Label(buttons, SWT.NONE);
            l.setText("X Axis Variation");
            final Combo xAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            xAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            xAxis.setItems(new String[] { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" });
            xAxis.select(2);
            xAxis.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String item = xAxis.getItem(xAxis.getSelectionIndex());
                    layouter.setOption(DefaultLayouter.X_AXIS_VARIATION, Integer.parseInt(item));

                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });

            l = new Label(buttons, SWT.NONE);
            l.setText("Y Axis Variation");
            final Combo yAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            yAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            yAxis.setItems(new String[] { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" });
            yAxis.select(1);
            yAxis.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String item = yAxis.getItem(yAxis.getSelectionIndex());
                    layouter.setOption(DefaultLayouter.Y_AXIS_VARIATION, Integer.parseInt(item));
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });

            Button run = new Button(buttons, SWT.NONE);
            run.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            run.setText("Re-Position");
            run.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                            viewer.getControl().getShell());
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                    dialog.getProgressMonitor().beginTask("Layouting tag cloud...", 100);
                    viewer.reset(dialog.getProgressMonitor(), false);
                    dialog.close();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            Button layout = new Button(buttons, SWT.NONE);
            layout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            layout.setText("Re-Layout");
            layout.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(viewer.getControl().getShell());
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                    dialog.getProgressMonitor().beginTask("Layouting tag cloud...", 200);
                    viewer.setInput(viewer.getInput(), dialog.getProgressMonitor());
                    //viewer.reset(dialog.getProgressMonitor(),false);
                    dialog.close();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            return buttons;
        };

    };
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    options.setLayoutData(gd);
}

From source file:org.eclipse.gef4.cloudio.internal.ui.actions.LoadFileAction.java

License:Open Source License

@Override
public void run(IAction action) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);

    dialog.setText("Select text file...");
    String sourceFile = dialog.open();
    if (sourceFile == null)
        return;//from w  w  w. ja  v a  2s.  c o m
    ProgressMonitorDialog pd = new ProgressMonitorDialog(getShell());
    try {
        List<Type> types = TypeCollector.getData(new File(sourceFile), "UTF-8");
        pd.setBlockOnOpen(false);
        pd.open();
        pd.getProgressMonitor().beginTask("Generating cloud...", 200);
        TagCloudViewer viewer = getViewer();
        viewer.setInput(types, pd.getProgressMonitor());
        // viewer.getCloud().layoutCloud(pd.getProgressMonitor(), false);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        pd.close();
    }
}

From source file:org.eclipse.gef4.cloudio.internal.ui.view.TagCloudView.java

License:Open Source License

private void createSideTab(SashForm form) {
    Composite parent = new Composite(form, SWT.NONE);
    parent.setLayout(new GridLayout());
    parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    options = new CloudOptionsComposite(parent, SWT.NONE, viewer) {

        protected Group addMaskButton(Composite parent) {
            Group buttons = new Group(parent, SWT.SHADOW_IN);
            buttons.setLayout(new GridLayout(2, true));
            buttons.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            Label l = new Label(buttons, SWT.NONE);
            l.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
            l.setText("Mask");
            Button file = new Button(buttons, SWT.FLAT);
            file.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
            file.setText("Open...");
            file.addListener(SWT.Selection, new Listener() {

                @Override// w w  w  .j a  va 2s  . c  o m
                public void handleEvent(Event event) {
                    FileDialog fd = new FileDialog(getShell(), SWT.OPEN);

                    fd.setText("Select a square b&w png image as mask...");
                    String sourceFile = fd.open();
                    if (sourceFile == null)
                        return;
                    try {
                        ImageLoader loader = new ImageLoader();
                        BufferedInputStream in = new BufferedInputStream(
                                new FileInputStream(new File(sourceFile)));
                        ImageData[] data = loader.load(in);
                        in.close();
                        viewer.getCloud().setBackgroundMask(data[0]);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }

            });
            return buttons;
        }

        protected void addGroups() {
            addMaskButton(this);
            super.addGroups();
        }

        protected Group addLayoutButtons(Composite parent) {
            Group buttons = super.addLayoutButtons(parent);

            Label l = new Label(buttons, SWT.NONE);
            l.setText("Scale");
            final Combo scale = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            scale.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            scale.setItems(new String[] { "linear", "logarithmic" });
            scale.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    switch (scale.getSelectionIndex()) {
                    case 0:
                        labelProvider.setScale(TypeLabelProvider.Scaling.LINEAR);
                        break;
                    case 1:
                        labelProvider.setScale(TypeLabelProvider.Scaling.LOGARITHMIC);
                        break;
                    default:
                        break;
                    }
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            scale.select(1);
            l = new Label(buttons, SWT.NONE);
            l.setText("X Axis Variation");
            final Combo xAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            xAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            xAxis.setItems(new String[] { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" });
            xAxis.select(2);
            xAxis.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String item = xAxis.getItem(xAxis.getSelectionIndex());
                    layouter.setOption(DefaultLayouter.X_AXIS_VARIATION, Integer.parseInt(item));

                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });

            l = new Label(buttons, SWT.NONE);
            l.setText("Y Axis Variation");
            final Combo yAxis = new Combo(buttons, SWT.DROP_DOWN | SWT.READ_ONLY);
            yAxis.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
            yAxis.setItems(new String[] { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" });
            yAxis.select(1);
            yAxis.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    String item = yAxis.getItem(yAxis.getSelectionIndex());
                    layouter.setOption(DefaultLayouter.Y_AXIS_VARIATION, Integer.parseInt(item));
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });

            Button run = new Button(buttons, SWT.NONE);
            run.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            run.setText("Re-Position");
            run.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(
                            viewer.getControl().getShell());
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                    dialog.getProgressMonitor().beginTask("Layouting tag cloud...", 100);
                    viewer.reset(dialog.getProgressMonitor(), false);
                    dialog.close();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            Button layout = new Button(buttons, SWT.NONE);
            layout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            layout.setText("Re-Layout");
            layout.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(viewer.getControl().getShell());
                    dialog.setBlockOnOpen(false);
                    dialog.open();
                    dialog.getProgressMonitor().beginTask("Layouting tag cloud...", 200);
                    viewer.setInput(viewer.getInput(), dialog.getProgressMonitor());
                    // viewer.reset(dialog.getProgressMonitor(),false);
                    dialog.close();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            return buttons;
        };

    };
    GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
    options.setLayoutData(gd);
}

From source file:org.eclipse.rap.examples.pages.DialogExamplePage.java

License:Open Source License

private void showProgressDialog() {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell()) {
        @Override//from  w  w w. j  av a  2  s.co  m
        public boolean close() {
            return super.close();
        }
    };
    dialog.setBlockOnOpen(false);
    try {
        dialog.run(true, true, new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Counting to 12...", 12);
                for (int i = 1; !monitor.isCanceled() && i <= 12; i++) {
                    monitor.worked(1);
                    Thread.sleep(300);
                }
                monitor.done();
            }
        });
    } catch (Exception e) {
        MessageDialogUtil.openError(getShell(), "Error", e.getMessage(), null);
    }
}