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

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

Introduction

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

Prototype

public ProgressMonitorDialog(Shell parent) 

Source Link

Document

Creates a progress monitor dialog under the given shell.

Usage

From source file:com.osp.debugger.launch.shortcut.OSPSimulLaunchShortcut.java

License:Open Source License

private void searchAndLaunchProgress(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;/*  w  w w.j a v a 2 s  . c  o  m*/
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List results = new ArrayList();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
                    try {
                        IProgressMonitor sub = new SubProgressMonitor(pm, 1);
                        for (int i = 0; i < nElements; i++) {
                            if (elements[i] instanceof IAdaptable) {
                                IResource r = (IResource) ((IAdaptable) elements[i])
                                        .getAdapter(IResource.class);
                                if (r != null) {
                                    ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                    if (cproject != null) {
                                        try {
                                            IBinary[] bins = cproject.getBinaryContainer().getBinaries();

                                            for (int j = 0; j < bins.length; j++) {
                                                if (bins[j].isSharedLib()) {
                                                    IPath path = bins[j].getPath().removeLastSegments(1);
                                                    if (path != null) {
                                                        String dirName = path.lastSegment();
                                                        if (dirName != null && dirName
                                                                .equals(IConstants.CONFIG_SIMUAL_DEBUG_DIR))
                                                            results.add(bins[j]);
                                                    }
                                                }
                                            }
                                        } catch (CModelException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = (IBinary) results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}

From source file:com.osp.debugger.launch.shortcut.OSPTargetLaunchShortcut.java

License:Open Source License

/**
 * Method searchAndLaunch.//ww  w.ja va  2s  .  co  m
 * @param objects
 * @param mode
 */
protected void searchAndLaunch(final Object[] elements, String mode) {
    if (elements != null && elements.length > 0) {
        IBinary bin = null;
        if (elements.length == 1 && elements[0] instanceof IBinary) {
            bin = (IBinary) elements[0];
        } else {
            final List results = new ArrayList();
            ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {
                public void run(IProgressMonitor pm) throws InterruptedException {
                    int nElements = elements.length;
                    pm.beginTask("Looking for executables", nElements); //$NON-NLS-1$
                    try {
                        IProgressMonitor sub = new SubProgressMonitor(pm, 1);
                        for (int i = 0; i < nElements; i++) {
                            if (elements[i] instanceof IAdaptable) {
                                IResource r = (IResource) ((IAdaptable) elements[i])
                                        .getAdapter(IResource.class);
                                if (r != null) {
                                    ICProject cproject = CoreModel.getDefault().create(r.getProject());
                                    if (cproject != null) {

                                        try {
                                            IBinary[] bins = cproject.getBinaryContainer().getBinaries();

                                            for (int j = 0; j < bins.length; j++) {
                                                if (bins[j].isSharedLib()) {
                                                    IPath path = bins[j].getPath().removeLastSegments(1);
                                                    if (path != null) {
                                                        String dirName = path.lastSegment();
                                                        if (dirName != null && dirName.startsWith(
                                                                IConstants.CONFIG_TARGET_DIR_PREFIX)) {
                                                            results.add(bins[j]);
                                                        }
                                                    }
                                                }
                                            }
                                        } catch (CModelException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            }
                            if (pm.isCanceled()) {
                                throw new InterruptedException();
                            }
                            sub.done();
                        }
                    } finally {
                        pm.done();
                    }
                }
            };
            try {
                dialog.run(true, true, runnable);
            } catch (InterruptedException e) {
                return;
            } catch (InvocationTargetException e) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        e.getMessage());
                return;
            }
            int count = results.size();
            if (count == 0) {
                MessageDialog.openError(getShell(),
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                        OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_binaries")); //$NON-NLS-1$
            } else if (count > 1) {
                bin = chooseBinary(results, mode);
            } else {
                bin = (IBinary) results.get(0);
            }
        }
        if (bin != null) {
            launch(bin, mode);
        }
    } else {
        MessageDialog.openError(getShell(),
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Application_Launcher"), //$NON-NLS-1$
                OspLaunchMessages.getString("CApplicationLaunchShortcut.Launch_failed_no_project_selected")); //$NON-NLS-1$
    }
}

From source file:com.oubeichen.gefexp.ShapesEditor.java

License:Open Source License

@Override
public void doSaveAs() {
    // Show a SaveAs dialog
    Shell shell = getSite().getWorkbenchWindow().getShell();
    SaveAsDialog dialog = new SaveAsDialog(shell);
    dialog.setOriginalFile(((IFileEditorInput) getEditorInput()).getFile());
    dialog.open();/*from   ww w.  j  a  v a  2 s.  c om*/

    IPath path = dialog.getResult();
    if (path != null) {
        // try to save the editor's contents under a different file name
        final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        try {
            new ProgressMonitorDialog(shell).run(false, // don't fork
                    false, // not cancelable
                    new WorkspaceModifyOperation() { // run this operation
                        @Override
                        public void execute(final IProgressMonitor monitor) {
                            ByteArrayOutputStream out = new ByteArrayOutputStream();
                            try {
                                if (!file.getName().contains(".raw.obsp")) {
                                    createOutputStream(out);
                                } else {
                                    createRawOutput(out);
                                }
                                file.create(new ByteArrayInputStream(out.toByteArray()), // contents
                                        true, // keep saving, even if
                                        // IFile
                                        // is out of sync with
                                        // the
                                        // Workspace
                                        monitor); // progress monitor
                            } catch (CoreException ce) {
                                ce.printStackTrace();
                            } catch (IOException ioe) {
                                ioe.printStackTrace();
                            }
                        }
                    });
            // set input to the new file
            setInput(new FileEditorInput(file));
            getCommandStack().markSaveLocation();
        } catch (InterruptedException ie) {
            // should not happen, since the monitor dialog is not cancelable
            ie.printStackTrace();
        } catch (InvocationTargetException ite) {
            ite.printStackTrace();
        }
    }
}

From source file:com.qcenzo.tools.localize.popup.actions.Localize.java

License:Open Source License

public void run(IAction action) {
    try {//w  w  w .  ja va2 s .c  o  m
        if (_selected == null) {
            MessageDialog.openInformation(_shell, "Error", "Fail to localize.");
            return;
        }

        IPreferenceStore store = Activator.getDefault().getPreferenceStore();

        _extensionsPattern = Pattern.compile(store.getString(LocalizationPreferenceConstants.EXTENSIONS)
                .replaceAll("[\\s" + "|]+", "").replaceAll(";+", "|").toLowerCase());

        _node = _nodePicker = new Node();
        findFile(Paths.get(_selected.getLocation().toOSString()));

        _translatorPattern = Pattern
                .compile(refine(store.getString(LocalizationPreferenceConstants.REGEX).getBytes()));

        TranslatorManager.getInstance().init(store.getString(LocalizationPreferenceConstants.TRANSLATOR),
                store.getInt(LocalizationPreferenceConstants.FROMTO));

        new ProgressMonitorDialog(_shell).run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    int current = 1;
                    monitor.beginTask("Localizing...(" + current + "/" + Node.number + ")",
                            IProgressMonitor.UNKNOWN);

                    while (_node.path != null) {
                        if (monitor.isCanceled())
                            monitor.done();

                        monitor.setTaskName("Localizing...(" + (current++) + "/" + Node.number + ")");
                        monitor.subTask(_node.path.toString());

                        translate(_node.path);

                        _node = _node.next;
                    }
                    monitor.done();
                } catch (Throwable e) {
                    monitor.done();
                }
            }
        });

        Node.number = 0;

        IHandlerService s = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
        s.executeCommand("org.eclipse.ui.file.refresh", null);
    } catch (Throwable e) {
    }
}

From source file:com.quantcomponents.ui.marketdata.NewHistoricalData.java

License:Open Source License

private List<IContract> searchContracts() {
    final List<IContract> contractList = new ArrayList<IContract>();
    try {//  w w w  .  ja v a2s .  c  o  m
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.setCancelable(true);
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    contractList.addAll(marketDataManager.searchContracts(contractCriteria,
                            new TaskMonitorAdapter(monitor, "Searching contracts...")));
                } catch (ConnectException e) {
                    throw new InvocationTargetException(e);
                } catch (RequestFailedException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (Exception e) {
        MessageDialog.openError(getShell(), "Error", "Contract search error: " + LangUtils.exceptionMessage(e));
        return Collections.emptyList();
    }
    if (contractList == null || contractList.isEmpty()) {
        MessageDialog.openError(this.getShell(), "No results",
                "Search for contracts returned empty set. Please revise your criteria");
        return Collections.emptyList();
    }
    return contractList;
}

From source file:com.quantcomponents.ui.marketdata.NewHistoricalData.java

License:Open Source License

private void retrieveHistoricalData(final IStockDatabase stockDatabase, final Date startDateTime,
        final Date endDateTime) throws InvocationTargetException, InterruptedException {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    dialog.setCancelable(true);// w  ww.ja va 2 s .  c o  m
    dialog.run(true, true, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                ITaskMonitor taskMonitor = new TaskMonitorAdapter(monitor, "Retrieving historical data...");
                marketDataManager.fillHistoricalData(stockDatabase, startDateTime, endDateTime, taskMonitor);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
}

From source file:com.quantcomponents.ui.marketdata.NewHistoricalData.java

License:Open Source License

private void startAutoUpdate(final IStockDatabase stockDatabase)
        throws InvocationTargetException, InterruptedException {
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    dialog.setCancelable(true);/*from  w w  w . ja  v a2 s  . co m*/
    final IRealTimeMarketDataManager realTimeMarketDataManager = (IRealTimeMarketDataManager) marketDataManager;
    dialog.run(true, true, new IRunnableWithProgress() {
        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                ITaskMonitor taskMonitor = new TaskMonitorAdapter(monitor, "Starting auto-update...");
                realTimeMarketDataManager.startRealtimeUpdate(stockDatabase, true, taskMonitor);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    });
}

From source file:com.quantcomponents.ui.marketdata.TimeChartDialog.java

License:Open Source License

private boolean executeChange() {
    final Date newStartDate = getStartDate();
    final Date newEndDate = getEndDate();
    try {//from   ww  w. ja v  a 2s  . c o  m
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.setCancelable(true);
        dialog.run(true, true, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    chartModel.setSuspendUpdates(true);
                    stockDatabase.getParent().fillHistoricalData(stockDatabase, newStartDate, newEndDate,
                            new TaskMonitorAdapter(monitor, "Retrieving historical data..."));
                    chartModel.setSuspendUpdates(false);
                } catch (Exception e) {
                    MessageDialog.openError(getShell(), "Error",
                            "Error while retrieving historical data: " + LangUtils.exceptionMessage(e));
                }
            }
        });
    } catch (InvocationTargetException e) {
        MessageDialog.openError(getShell(), "Error", "A problem occurred while retrieving historical data");
        return false;
    } catch (InterruptedException e) {
        MessageDialog.openError(getShell(), "Error",
                "Task interrupted while retrieving historical data: " + LangUtils.exceptionMessage(e));
        return false;
    }
    if (isMovingWindow()) {
        chartModel.setFixedDurationWindow(newStartDate, tradingCalendar);
    } else {
        chartModel.setFixedWindow(newStartDate, newEndDate, tradingCalendar);
    }
    return true;
}

From source file:com.runwaysdk.manager.general.MainWindow.java

License:Open Source License

@Override
public void run(IRunnableWithProgress worker) {
    try {//  w w  w . j av a  2  s .c o m
        new ProgressMonitorDialog(this.getShell()).run(true, false, worker);
    } catch (InvocationTargetException e) {
        MainWindow.this.getConfiguration().handleError(e);
    } catch (Exception e) {
        MainWindow.this.getConfiguration().handleError(e);
    }
}

From source file:com.runwaysdk.manager.general.MainWindow.java

License:Open Source License

@Override
public boolean close() {

    for (IModule module : modules) {
        module.shellCloseEvent();//  w w w  .ja v  a 2s.co  m
    }

    try {
        new ProgressMonitorDialog(getShell()).run(true, false, new IRunnableWithProgress() {
            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(Localizer.getMessage("MANAGER_SHUTDOWN"), IProgressMonitor.UNKNOWN);

                shutdown();

                monitor.done();
            }
        });
    } catch (Exception e) {
        // An exception occured while showing a dialog about the progress of
        // shutting down the cache. Ensure that the cache gets shutdown without
        // the dialog.
        this.error(e);

        return false;
    }

    return super.close();
}