Java Code Examples for org.eclipse.core.runtime.jobs.Job#setUser()

The following examples show how to use org.eclipse.core.runtime.jobs.Job#setUser() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SendFileAction.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
  JID jid = getSelectedJID();
  if (jid == null) return;

  FileDialog fd = new FileDialog(SWTUtils.getShell(), SWT.OPEN);
  fd.setText(Messages.SendFileAction_filedialog_text);

  String filename = fd.open();
  if (filename == null) return;

  File file = new File(filename);
  if (file.isDirectory()) return;

  Job job = new OutgoingFileTransferJob(jid, file);
  job.setUser(true);
  job.schedule();
}
 
Example 2
Source File: DeployDiagramHandler.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void runInJob(DiagramFileStore diagramFileStore, DeployProcessOperation deployOperation) {
    Job deployJob = new Job(String.format(Messages.deployingProcessesFrom, diagramFileStore.getName())) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            return deployOperation.run(monitor);
        }
    };
    deployJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            Display.getDefault().syncExec(() -> displayDeployResult(event.getResult()));
        }
    });
    deployJob.setUser(true);
    deployJob.schedule();
}
 
Example 3
Source File: ExportToTextCommandHandler.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<TmfEventTableColumn> columns = getColumns(event.getApplicationContext());
    ITmfTrace trace = TmfTraceManager.getInstance().getActiveTrace();
    ITmfFilter filter = TmfTraceManager.getInstance().getCurrentTraceContext().getFilter();
    if (trace != null) {
        FileDialog fd = TmfFileDialogFactory.create(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.SAVE);
        fd.setFilterExtensions(new String[] { "*.csv", "*.*", "*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        fd.setOverwrite(true);
        final String s = fd.open();
        if (s != null) {
            Job j = new ExportToTextJob(trace, filter, columns, s);
            j.setUser(true);
            j.schedule();
        }
    }
    return null;
}
 
Example 4
Source File: RenderJobRunner.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public static void runRenderJob( Job runJob, RenderJobRule jobRule )
{
	// boolean showDialog = true;
	// if ( Display.getCurrent( ) == null )
	// showDialog = false;
	//
	// Shell shell = PlatformUI.getWorkbench( )
	// .getActiveWorkbenchWindow( )
	// .getShell( );

	// if ( showDialog )
	// {
	// service.showInDialog( shell, runJob );
	// }

	// runJob.setProperty( IProgressConstants.ICON_PROPERTY, image );
	runJob.setUser( true );
	runJob.setRule( jobRule );
	runJob.schedule( );
}
 
Example 5
Source File: EclipseRefreshAndBuildHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) {
   
    Job job = new Job("[y] Platform Refresh and Build"){
        @Override
        protected IStatus run(IProgressMonitor monitor){
            
        	try
        	{
        		refreshAndFullBuild(monitor);
        		monitor.done();
	            return Status.OK_STATUS;
        	}
        	catch (Exception e)
        	{
        		throw new IllegalStateException("Failed to synchronize with the platform, see workspace logs for details", e);
        	}
        	
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
 
Example 6
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void scheduleJob(final IBaseClosure<Void, CoreException> jobRunnable, ISchedulingRule rule, String jobCaption, boolean user) {
	Job job = new Job(jobCaption) {
		public IStatus run(IProgressMonitor monitor) {
			try {
				jobRunnable.execute(null);
			} catch (CoreException e) {
				LogHelper.logError(e);
			}
			return Status.OK_STATUS;
		}
	};
	job.setRule(rule);
	job.setUser(user);
	job.schedule();
}
 
Example 7
Source File: HelloWorldValidatorConfigurationBlock.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob("Validation Settings Changed", project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;
}
 
Example 8
Source File: TaskTagConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob("Rebuild", project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;
}
 
Example 9
Source File: AbstractValidatorConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.15
 */
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob(
			Messages.ValidationConfigurationBlock_build_job_title, project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;

}
 
Example 10
Source File: XtextValidatorConfigurationBlock.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected Job getBuildJob(IProject project) {
	Job buildJob = new OptionsConfigurationBlock.BuildJob(Messages.XtextValidatorConfigurationBlock_11, project);
	buildJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
	buildJob.setUser(true);
	return buildJob;

}
 
Example 11
Source File: ConvertToJava8RuntimeHandler.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
  List<IProject> projects = ProjectFromSelectionHelper.getProjects(event);
  Preconditions.checkArgument(!projects.isEmpty());
  Job updateJob = new WorkspaceJob(Messages.getString("reconfiguringToJava8")) { // $NON-NLS-1$
        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
          SubMonitor progress = SubMonitor.convert(monitor, projects.size());
          for (IProject project : projects) {
            progress.subTask(
                Messages.getString("reconfiguringProject", project.getName())); // $NON-NLS-1$
            IFile appEngineWebXml =
                AppEngineConfigurationUtil.findConfigurationFile(project, APPENGINE_DESCRIPTOR);
            if (appEngineWebXml != null) {
              // add the <runtime> and the rest should be handled for us
              AppEngineDescriptorTransform.addJava8Runtime(appEngineWebXml);
            }
            progress.worked(1);
          }
          return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
          return super.belongsTo(family)
              || J2EEElementChangedListener.PROJECT_COMPONENT_UPDATE_JOB_FAMILY.equals(family);
        }
      };
  updateJob.setRule(getWorkspaceRoot());
  updateJob.setUser(true);
  updateJob.schedule();
  return null;
}
 
Example 12
Source File: CloudSdkManager.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Triggers the update of a managed Cloud SDK, if the preferences are configured to auto-manage
 * the SDK.
 */
public void updateManagedSdkAsync() {
  if (CloudSdkPreferences.isAutoManaging()) {
    // Keep installation failure as ERROR so that failures are reported
    Job updateJob = new CloudSdkUpdateJob(null /* create new message console */, modifyLock);
    updateJob.setUser(false);
    updateJob.schedule();
  }
}
 
Example 13
Source File: PydevConsoleFactory.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void createConsole(final PydevConsoleInterpreter interpreter, final String additionalInitialComands) {

        Job job = new Job("Create Interactive Console") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                monitor.beginTask("Create Interactive Console", 4);
                try {
                    sayHello(interpreter, new SubProgressMonitor(monitor, 1));
                    connectDebugger(interpreter, additionalInitialComands, new SubProgressMonitor(monitor, 2));
                    enableGuiEvents(interpreter, new SubProgressMonitor(monitor, 1));
                    return Status.OK_STATUS;
                } catch (Exception e) {
                    try {
                        interpreter.close();
                    } catch (Exception e_inner) {
                        // ignore, but log nested exception
                        Log.log(e_inner);
                    }
                    if (e instanceof UserCanceledException) {
                        return Status.CANCEL_STATUS;
                    } else {
                        Log.log(e);
                        return PydevDebugPlugin.makeStatus(IStatus.ERROR, "Error initializing console.", e);
                    }

                } finally {
                    monitor.done();
                }

            }
        };
        job.setUser(true);
        job.schedule();
    }
 
Example 14
Source File: UpdateCheck.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
public Job check(String binaryPath) {
	Job job = new UpdateCheckJob(binaryPath);
	job.setUser(true);
	// execute job asynchronously
	job.schedule();
	return job;
}
 
Example 15
Source File: ExecuteCommandScriptHandler.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    TraceSessionGroup tmpGroup = null;

    fLock.lock();
    try {
        tmpGroup = fSessionGroup;
    } finally {
        fLock.unlock();
    }

    final TraceSessionGroup sessionGroup = tmpGroup;
    if (sessionGroup == null) {
        return null;
    }

    // Open dialog box for the node name and address
    final ISelectCommandScriptDialog dialog = TraceControlDialogFactory.getInstance().getCommandScriptDialog();

    if (dialog.open() != Window.OK) {
        return null;
    }

    Job job = new Job(Messages.TraceControl_ExecuteScriptJob) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                sessionGroup.executeCommands(monitor, dialog.getCommands());
            } catch (ExecutionException e) {
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateSessionFailure, e);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
 
Example 16
Source File: BuilderUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private static Job configureAndSchedule(Job buildJob) {
	buildJob.setUser(true);
	buildJob.schedule();
	return buildJob;
}
 
Example 17
Source File: DestroySessionHandler.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    if (window == null) {
        return false;
    }

    List<TraceSessionComponent> tmpSessions = new ArrayList<>();

    // Make a copy of the session list to avoid concurrent modification
    // of the list of sessions
    fLock.lock();
    try {
        tmpSessions.addAll(fSessions);
    } finally {
        fLock.unlock();
    }
    final List<TraceSessionComponent> sessions = tmpSessions;

    // Get user confirmation
    IConfirmDialog dialog = TraceControlDialogFactory.getInstance().getConfirmDialog();
    if (!dialog.openConfirm(window.getShell(),
            Messages.TraceControl_DestroyConfirmationTitle,
            Messages.TraceControl_DestroyConfirmationMessage)) {

        return null;
    }

    Job job = new Job(Messages.TraceControl_DestroySessionJob) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                for (TraceSessionComponent session : sessions) {
                    // Destroy all selected sessions
                    TraceSessionGroup sessionGroup = (TraceSessionGroup)session.getParent();
                    sessionGroup.destroySession(session, monitor);
                }
            } catch (ExecutionException e) {
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_DestroySessionFailure, e);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();

    return null;
}
 
Example 18
Source File: BaseEnableChannelHandler.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    CommandParameter tmpParam = null;

    fLock.lock();
    try {
        tmpParam = fParam;
        if (tmpParam == null) {
            return null;
        }
        tmpParam = tmpParam.clone();
    } finally {
        fLock.unlock();
    }
    final CommandParameter param = tmpParam;

    final IEnableChannelDialog dialog =  TraceControlDialogFactory.getInstance().getEnableChannelDialog();
    dialog.setTargetNodeComponent(param.getSession().getTargetNode());
    dialog.setDomainComponent(getDomain(param));
    dialog.setHasKernel(param.getSession().hasKernelProvider());

    if (dialog.open() != Window.OK) {
        return null;
    }

    Job job = new Job(Messages.TraceControl_CreateChannelStateJob) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            Exception error = null;

            List<String> channelNames = new ArrayList<>();
            channelNames.add(dialog.getChannelInfo().getName());

            try {
                enableChannel(param, channelNames, dialog.getChannelInfo(), dialog.getDomain(), monitor);
            } catch (ExecutionException e) {
                error = e;
            }

            // refresh in all cases
            refresh(param);

            if (error != null) {
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_CreateChannelStateFailure, error);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();

    return null;
}
 
Example 19
Source File: AssignEventHandler.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    // Make a copy for thread safety
    Parameter tmpParam = null;
    fLock.lock();
    try {
        tmpParam = fParam;
        if (tmpParam == null)  {
            return null;
        }
        tmpParam = new Parameter(tmpParam);
    } finally {
        fLock.unlock();
    }
    final Parameter param = tmpParam;

    // Open dialog box to retrieve the session and channel where the events should be enabled in.
    final IGetEventInfoDialog dialog = TraceControlDialogFactory.getInstance().getGetEventInfoDialog();
    dialog.setDomain(param.getDomain());
    dialog.setSessions(param.getSessions());

    if (dialog.open() != Window.OK) {
        return null;
    }

    Job job = new Job(Messages.TraceControl_EnableEventsJob) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {

            Exception error = null;
            TraceSessionComponent session = dialog.getSession();
            try {
                List<String> eventNames = new ArrayList<>();
                List<BaseEventComponent> events = param.getEvents();
                // Find the type of the events (all the events in the list are the same type)
                TraceEventType  eventType = !events.isEmpty() ? events.get(0).getEventType() : null;
                // Create list of event names
                for (Iterator<BaseEventComponent> iterator = events.iterator(); iterator.hasNext();) {
                    BaseEventComponent baseEvent = iterator.next();
                    eventNames.add(baseEvent.getName());
                }

                TraceChannelComponent channel = dialog.getChannel();
                if (TraceEventType.TRACEPOINT.equals(eventType)) {
                    if (channel == null) {
                        // enable events on default channel (which will be created by lttng-tools)
                        session.enableEvents(eventNames, param.getDomain(), dialog.getFilterExpression(), null, monitor);
                    } else {
                        channel.enableEvents(eventNames, dialog.getFilterExpression(), null, monitor);
                    }
                } else if (TraceEventType.SYSCALL.equals(eventType)) {
                    if (channel == null) {
                        session.enableSyscalls(eventNames, monitor);
                    } else {
                        channel.enableSyscalls(eventNames, monitor);
                    }
                }

            } catch (ExecutionException e) {
                error = e;
            }

            // refresh in all cases
            if (session != null) {
                refresh(new CommandParameter(session));
            }

            if (error != null) {
                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_EnableEventsFailure, error);
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();

    return null;
}
 
Example 20
Source File: SaveHandler.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    if (window == null) {
        return false;
    }

    fLock.lock();
    try {

        final List<TraceSessionComponent> sessions = new ArrayList<>();
        sessions.addAll(fSessions);

        // Open dialog box for the save dialog path
        final ISaveDialog dialog = TraceControlDialogFactory.getInstance().getSaveDialog();
        if (dialog.open() != Window.OK) {
            return null;
        }

        Job job = new Job(Messages.TraceControl_SaveJob) {
            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    for (TraceSessionComponent session : sessions) {
                        session.saveSession(null, null, dialog.isForce(), monitor);

                        final IRemoteConnection connection = session.getTargetNode().getRemoteSystemProxy().getRemoteConnection();
                        SubMonitor subMonitor = SubMonitor.convert(monitor, 3);
                        // create destination directory (if necessary)
                        IRemoteProcessService processService = connection.getService(IRemoteProcessService.class);
                        IPath path = null;
                        if (processService != null) {
                            String cwd = processService.getWorkingDirectory();
                            path = RemoteServicesUtils.posixPath(cwd);
                            path = path.append(LTTngControlServiceConstants.DEFAULT_PATH);
                        }

                        if (path == null) {
                            return Status.CANCEL_STATUS;
                        }

                        // upload file
                        IRemoteFileService fileService = connection.getService(IRemoteFileService.class);
                        if (fileService == null) {
                            return Status.CANCEL_STATUS;
                        }
                        IPath dest = LttngProfileManager.getProfilePath();
                        String profileName = session.getName() + ".lttng"; //$NON-NLS-1$
                        final Path destPath = FileSystems.getDefault().getPath(dest.toString()).resolve(profileName);
                        IFileStore destFileStore = EFS.getLocalFileSystem().fromLocalFile(destPath.toFile());
                        SubMonitor childMonitor = subMonitor.newChild(1);

                        IPath remotePath = RemoteServicesUtils.posixPath(path.toString()).append(profileName);
                        IFileStore remoteResource = fileService.getResource(remotePath.toString());
                        final boolean overwrite[] = new boolean[1];
                        if (destPath.toFile().exists()) {
                            Display.getDefault().syncExec(() -> overwrite[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(),
                                    Messages.TraceControl_ProfileAlreadyExists,
                                    NLS.bind(Messages.TraceControl_OverwriteQuery, destPath.getFileName())));

                            if (!overwrite[0]) {
                                continue;
                            }
                        }
                        remoteResource.copy(destFileStore, EFS.OVERWRITE, childMonitor);
                    }
                } catch (ExecutionException | CoreException e) {
                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_SaveFailure, e);
                }
                return Status.OK_STATUS;
            }
        };
        job.setUser(true);
        job.schedule();
    } finally {
        fLock.unlock();
    }
    return null;
}