Search in sources :

Example 11 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project generator by mybatis.

the class WorkspaceUtilities method createProject.

private static IProject createProject(String projectName) throws CoreException {
    final IProject project = getWorkspaceRoot().getProject(projectName);
    IWorkspaceRunnable create = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            project.create(null);
            project.open(null);
        }
    };
    getWorkspace().run(create, null);
    return project;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProject(org.eclipse.core.resources.IProject)

Example 12 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project mechanoid by robotoworks.

the class NewMechanoidElementWizard method performFinish.

@Override
public boolean performFinish() {
    final IPath newFilePath = createNewResourceFilePath();
    onBeforeCreateElementResource();
    WorkspaceModifyDelegatingOperation op = new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                mNewResource = createElementResource(monitor, newFilePath);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    });
    try {
        getContainer().run(true, true, op);
        selectAndReveal(mNewResource);
        openResource(mNewResource);
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), Messages.NewMechanoidElementWizard_Dialog_CreateResourceError_Title, realException.getMessage());
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) WorkspaceModifyDelegatingOperation(org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PartInitException(org.eclipse.ui.PartInitException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 13 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project gfm_viewer by satyagraha.

the class SchedulerDefault method scheduleTransformation.

@Override
public void scheduleTransformation(final File mdFile, final File htFile, final Callback<File> onDone) {
    final String jobName = "Transforming: " + mdFile.getName();
    Job job = new Job(jobName) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus status = Status.OK_STATUS;
            try {
                transformer.transformMarkdownFile(mdFile, htFile);
            } catch (IOException e) {
                status = new Status(Status.ERROR, pluginId, jobName, e);
            }
            return status;
        }
    };
    job.setUser(false);
    job.setSystem(false);
    job.setPriority(Job.SHORT);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            // refreshFile(htFile);
            if (event.getResult().isOK()) {
                if (onDone != null) {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            onDone.onComplete(htFile);
                        }
                    });
                }
            } else {
                // normal reporting has occurred
                if (onDone != null) {
                    final Throwable exception = event.getResult().getException();
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            onDone.onError(htFile, exception);
                        }
                    });
                }
            }
        }
    });
    job.schedule();
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IOException(java.io.IOException) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job)

Example 14 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project dbeaver by serge-rider.

the class NavigatorHandlerCreateLink method createLink.

private void createLink(IWorkbenchWindow workbenchWindow, IFolder folder, String fsFolder) {
    final File externalFolder = new File(fsFolder);
    try {
        final IFolder linkedFolder = folder.getFolder(externalFolder.getName());
        workbenchWindow.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    linkedFolder.createLink(externalFolder.toURI(), IResource.NONE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        UIUtils.showErrorDialog(workbenchWindow.getShell(), "Create link", "Can't create link", e);
    } catch (InterruptedException e) {
    // skip
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IFolder(org.eclipse.core.resources.IFolder) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 15 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project dbeaver by serge-rider.

the class ProgressPageControl method createSearchControls.

private void createSearchControls() {
    if (searchText != null) {
        return;
    }
    hideControls(false);
    ((GridLayout) searchControlsComposite.getLayout()).numColumns = 2;
    searchText = new Text(searchControlsComposite, SWT.BORDER);
    UIUtils.addFocusTracker(DBeaverUI.getActiveWorkbenchWindow(), UIUtils.INLINE_WIDGET_EDITOR_ID, this.searchText);
    if (curSearchText != null) {
        searchText.setText(curSearchText);
        searchText.setSelection(curSearchText.length());
    }
    //searchText.setBackground(searchNotFoundColor);
    searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    searchText.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            switch(e.keyCode) {
                case SWT.ESC:
                    cancelSearch(true);
                    break;
                case SWT.CR:
                case SWT.ARROW_UP:
                case SWT.ARROW_DOWN:
                    if (childPageControl != null) {
                        childPageControl.setFocus();
                    }
                    e.doit = false;
                    //performSearch(SearchType.NEXT);
                    break;
            }
        }
    });
    searchText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            curSearchText = searchText.getText();
            if (curSearchJob == null) {
                curSearchJob = new UIJob(CoreMessages.controls_progress_page_job_search) {

                    @Override
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        if (monitor.isCanceled()) {
                            return Status.CANCEL_STATUS;
                        }
                        performSearch(SearchType.NEXT);
                        curSearchJob = null;
                        return Status.OK_STATUS;
                    }
                };
                curSearchJob.schedule(200);
            }
        }
    });
    //ToolBar searchTools = new ToolBar(searchControlsComposite, SWT.HORIZONTAL);
    if (searchToolbarManager == null) {
        searchToolbarManager = new ToolBarManager(SWT.FLAT | SWT.HORIZONTAL);
        // Do not add prev/next buttons - they doesn't make sense now.
        // Keep code just in case
        /*
            searchToolbarManager.add(ActionUtils.makeCommandContribution(
                    PlatformUI.getWorkbench(),
                    IWorkbenchActionDefinitionIds.FIND_NEXT,
                    null,
                    UIIcon.ARROW_DOWN));
            searchToolbarManager.add(ActionUtils.makeCommandContribution(
                    PlatformUI.getWorkbench(),
                    IWorkbenchActionDefinitionIds.FIND_PREVIOUS,
                    null,
                    UIIcon.ARROW_UP));
*/
        searchToolbarManager.add(new Action(CoreMessages.controls_progress_page_action_close, UIUtils.getShardImageDescriptor(ISharedImages.IMG_ELCL_REMOVE)) {

            @Override
            public void run() {
                cancelSearch(true);
            }
        });
    }
    searchToolbarManager.createControl(searchControlsComposite);
    searchControlsComposite.getParent().layout();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Action(org.eclipse.jface.action.Action) GridData(org.eclipse.swt.layout.GridData) UIJob(org.eclipse.ui.progress.UIJob) ToolBarManager(org.eclipse.jface.action.ToolBarManager)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)392 InvocationTargetException (java.lang.reflect.InvocationTargetException)152 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)144 CoreException (org.eclipse.core.runtime.CoreException)104 IStatus (org.eclipse.core.runtime.IStatus)85 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)74 ArrayList (java.util.ArrayList)73 Status (org.eclipse.core.runtime.Status)65 Job (org.eclipse.core.runtime.jobs.Job)57 IOException (java.io.IOException)54 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)53 ITask (com.cubrid.common.core.task.ITask)49 IFile (org.eclipse.core.resources.IFile)46 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)43 File (java.io.File)42 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)41 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 PersistenceException (org.talend.commons.exception.PersistenceException)36 IProject (org.eclipse.core.resources.IProject)33