Java Code Examples for org.eclipse.core.runtime.IProgressMonitor#worked()

The following examples show how to use org.eclipse.core.runtime.IProgressMonitor#worked() . 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: DocumentPart.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 进度条前进处理类,若返回false,则标志退出程序的执行
 * @param monitor
 * @param traverPIdx
 * @param last
 * @return ;
 */
public boolean monitorWork(IProgressMonitor monitor, int traverPIdx, boolean last){
	if (last) {
		if (traverPIdx % workInterval != 0) {
			if (monitor.isCanceled()) {
				throw new OperationCanceledException(Messages.getString("docxConvert.task3"));
			}
			monitor.worked(1);
		}
	}else {
		if (traverPIdx % workInterval == 0) {
			if (monitor.isCanceled()) {
				throw new OperationCanceledException(Messages.getString("docxConvert.task3"));
			}
			monitor.worked(1);
		}
	}
	return true;
	
}
 
Example 2
Source File: SplitTmx.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public void monitorWork(IProgressMonitor monitor, int traversalTuIndex, boolean last) throws Exception{
	if (last) {
		if (traversalTuIndex % workInterval != 0) {
			if (monitor.isCanceled()) {
				throw new OperationCanceledException();
			}
			monitor.worked(1);
		}
	}else {
		if (traversalTuIndex % workInterval == 0) {
			if (monitor.isCanceled()) {
				throw new OperationCanceledException();
			}
			monitor.worked(1);
		}
	}
}
 
Example 3
Source File: BillAllOpenCons.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int start(IProgressMonitor monitor){
	Integer count = 0;
	
	Query<Fall> qbe = new Query<Fall>(Fall.class);
	List<Fall> qre = qbe.execute();
	
	monitor.beginTask("Offene Konsultationen abrechnen und Fälle schliessen",
		qre.size());
	TimeTool now = new TimeTool();
	for (Fall fall : qre) {
		if (fall.isOpen()) {
			Rechnung.build(Arrays.asList(fall.getBehandlungen(false)));
			fall.setEndDatum(now.toString(TimeTool.DATE_GER));
			count++;
		}
		monitor.worked(1);
		if (monitor.isCanceled()) {
			return count;
		}
	}
	monitor.done();
	return count;
}
 
Example 4
Source File: Rtf2Xliff.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check segments.
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws SAXException
 *             the SAX exception
 */
private void checkSegments(IProgressMonitor monitor) throws IOException, SAXException {
	monitor.beginTask(Messages.getString("rtf.Rtf2Xliff.task11"), segments.size());
	monitor.subTask("");
	for (int i = 0; i < segments.size(); i++) {
		// 是否取消操作
		if (monitor.isCanceled()) {
			throw new OperationCanceledException(Messages.getString("rtf.cancel"));
		}
		String segment = segments.get(i);
		String trimmed = segment.trim();
		if (inExternal && trimmed.startsWith("\\pard")) { //$NON-NLS-1$
			inExternal = false;
		}
		processSegment(segment);
		monitor.worked(1);
	}
	monitor.done();
}
 
Example 5
Source File: NLSSearchResultRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void reportUnusedPropertyNames(IProgressMonitor pm) {
	//Don't use endReporting() for long running operation.
	pm.beginTask("", fProperties.size()); //$NON-NLS-1$
	boolean hasUnused= false;
	pm.setTaskName(NLSSearchMessages.NLSSearchResultRequestor_searching);
	FileEntry groupElement= new FileEntry(fPropertiesFile, NLSSearchMessages.NLSSearchResultCollector_unusedKeys);

	for (Enumeration<?> enumeration= fProperties.propertyNames(); enumeration.hasMoreElements();) {
		String propertyName= (String) enumeration.nextElement();
		if (!fUsedPropertyNames.contains(propertyName)) {
			addMatch(groupElement, propertyName);
			hasUnused= true;
		}
		pm.worked(1);
	}
	if (hasUnused)
		fResult.addFileEntryGroup(groupElement);
	pm.done();
}
 
Example 6
Source File: ProjectCompareTree.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Show the given comparison in the widget. All arguments may be <code>null</code>.
 *
 * @param comparison
 *            the comparison to show in the widget or <code>null</code> to clear the widget.
 * @param focusImplId
 *            the ID of a single implementation to focus on (all other implementations will be hidden; columns of
 *            index 2 and above will show additional information for this focus implementation) or <code>null</code>
 *            to show all available implementations side-by-side (but without additional information in separate
 *            columns).
 * @param monitor
 *            the progress monitor to use or <code>null</code>.
 */
public void setComparison(ProjectComparison comparison, N4JSProjectName focusImplId, IProgressMonitor monitor) {
	this.comparison = comparison;
	this.focusImplIndex = comparison != null && focusImplId != null ? comparison.getImplIndex(focusImplId) : -1;
	this.cachedDocumentation = null;

	// in case of a focus implementation, read documentation for API and the focus implementation into cache
	if (comparison != null && focusImplId != null) {
		if (monitor != null) {
			monitor.subTask("Scanning jsdoc ...");
			monitor.worked(1);
		}
		final int focusImplIdx = comparison.getImplIndex(focusImplId);
		cachedDocumentation = projectCompareTreeHelper.readDocumentation(comparison, new int[] { focusImplIdx });
	}

	if (monitor != null) {
		monitor.subTask("Updating UI ...");
		monitor.worked(1);
	}
	setInput(comparison);
	refreshColumnHeaders();
	expandAll();
}
 
Example 7
Source File: HierarchyBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void worked(IProgressMonitor monitor, int work) {
	if (monitor != null) {
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		} else {
			monitor.worked(work);
		}
	}
}
 
Example 8
Source File: CreateGhidraModuleProjectWizard.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a Ghidra module project.
 * 
 * @param ghidraInstallDir The Ghidra installation directory to use.
 * @param projectName The name of the project to create.
 * @param projectDir The project's directory.
 * @param createRunConfig Whether or not to create a new run configuration for the project.
 * @param runConfigMemory The run configuration's desired memory.  Could be null.
 * @param moduleTemplateTypes The desired module template types.
 * @param jythonInterpreterName The name of the Jython interpreter to use for Python support.
 *   Could be null if Python support is not wanted.
 * @param monitor The monitor to use during project creation.
 * @throws InvocationTargetException if an error occurred during project creation.
 */
private void create(File ghidraInstallDir, String projectName, File projectDir,
		boolean createRunConfig, String runConfigMemory,
		Set<ModuleTemplateType> moduleTemplateTypes, String jythonInterpreterName,
		IProgressMonitor monitor) throws InvocationTargetException {
	try {
		info("Creating " + projectName + " at " + projectDir);
		monitor.beginTask("Creating " + projectName, 3);

		GhidraApplicationLayout ghidraLayout = new GhidraApplicationLayout(ghidraInstallDir);
		monitor.worked(1);

		IJavaProject javaProject =
			GhidraModuleUtils.createGhidraModuleProject(projectName, projectDir,
				createRunConfig, runConfigMemory, ghidraLayout, jythonInterpreterName, monitor);
		monitor.worked(1);

		IFile sourceFile = GhidraModuleUtils.configureModuleSource(javaProject,
			projectDir, ghidraLayout, moduleTemplateTypes, monitor);
		monitor.worked(1);

		if (sourceFile != null) {
			EclipseMessageUtils.displayInEditor(sourceFile, workbench);
		}

		info("Finished creating " + projectName);
	}
	catch (IOException | ParseException | CoreException e) {
		throw new InvocationTargetException(e);
	}
	finally {
		monitor.done();
	}
}
 
Example 9
Source File: ClearMarkersAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void runWithProgress(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(getName(), resources.size());
    for (WorkItem res : resources) {
        monitor.subTask(res.getName());
        res.clearMarkers();
        monitor.worked(1);
    }
}
 
Example 10
Source File: MechanicService.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This is the main service entry point. Our job calls through directly
 * to this method when its corresponding run method is called.
 *
 * Here we scan for new tasks, test for compliance and send notifications
 * to other interested classes.
 */
private IStatus run(IProgressMonitor monitor) {

  // TODO(smckay): use the progress monitor to report task information
  monitor.beginTask("Updating Tasks", 3);
  try {
    update(monitor);
  } finally {
    reschedule();
  }
  monitor.worked(1);
  return Status.OK_STATUS;
}
 
Example 11
Source File: LinkGhidraWizard.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Links a Java project's classpath and external links to a Ghidra installation directory.
 *  
 * @param ghidraInstallDir The Ghidra installation directory to use.
 * @param javaProject The Java project to link.
 * @param jythonInterpreterName The name of the Jython interpreter to use for Python support.
 *   Could be null if Python support is not wanted.
 * @param monitor The monitor to use during project link.
 * @throws InvocationTargetException if an error occurred during link.
 */
private void link(File ghidraInstallDir, IJavaProject javaProject, String jythonInterpreterName,
		IProgressMonitor monitor) throws InvocationTargetException {
	IProject project = javaProject.getProject();
	try {
		info("Linking " + project.getName());
		monitor.beginTask("Linking " + project.getName(), 2);

		GhidraApplicationLayout ghidraLayout = new GhidraApplicationLayout(ghidraInstallDir);
		JavaConfig javaConfig =
			new JavaConfig(ghidraLayout.getApplicationInstallationDir().getFile(false));
		GhidraProjectUtils.linkGhidraToProject(javaProject, ghidraLayout, javaConfig,
			jythonInterpreterName, monitor);
		monitor.worked(1);

		project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
		monitor.worked(1);

		info("Finished linking " + project.getName());
	}
	catch (IOException | ParseException | CoreException e) {
		throw new InvocationTargetException(e);
	}
	finally {
		monitor.done();
	}
}
 
Example 12
Source File: TrpRtfBuilder.java    From TranskribusCore with GNU General Public License v3.0 5 votes vote down vote up
public static void writeRtfForDoc(TrpDoc doc, boolean wordBased, File file, Set<Integer> pageIndices, IProgressMonitor monitor) throws JAXBException, IOException {
	Rtf rtf = Rtf.rtf();	
	List<TrpPage> pages = doc.getPages();
	
	int totalPages = pageIndices==null ? pages.size() : pageIndices.size();
	if (monitor!=null) {
		monitor.beginTask("Exporting to RTF", totalPages);
	}
	
	int c=0;
	for (int i=0; i<pages.size(); ++i) {
		if (pageIndices!=null && !pageIndices.contains(i))
			continue;
		
		if (monitor!=null) {
			if (monitor.isCanceled()) {
				logger.debug("RTF export cancelled!");
				return;
			}
			monitor.subTask("Processing page "+(c+1));
		}
		TrpPage page = pages.get(i);
		TrpTranscriptMetadata md = page.getCurrentTranscript();
		JAXBPageTranscript tr = new JAXBPageTranscript(md);
		tr.build();			
		TrpPageType trpPage = tr.getPage();
		
		logger.debug("writing rtf for page "+(i+1)+"/"+doc.getNPages());
		rtf.section(getRtfParagraphsForTranscript(trpPage, wordBased));
				
		++c;
		if (monitor!=null) {
			monitor.worked(c);
		}
	}
	
	rtf.out( new FileWriter(file) );
	logger.info("wrote rtf to: "+file.getAbsolutePath());
}
 
Example 13
Source File: SelfEncapsulateFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
	final Map<String, String> arguments= new HashMap<String, String>();
	String project= null;
	IJavaProject javaProject= fField.getJavaProject();
	if (javaProject != null)
		project= javaProject.getElementName();
	int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
	final IType declaring= fField.getDeclaringType();
	try {
		if (declaring.isAnonymous() || declaring.isLocal())
			flags|= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
	} catch (JavaModelException exception) {
		JavaPlugin.log(exception);
	}
	final String description= Messages.format(RefactoringCoreMessages.SelfEncapsulateField_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
	final String header= Messages.format(RefactoringCoreMessages.SelfEncapsulateFieldRefactoring_descriptor_description, new String[] { JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED), JavaElementLabels.getElementLabel(declaring, JavaElementLabels.ALL_FULLY_QUALIFIED)});
	final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_original_pattern, JavaElementLabels.getElementLabel(fField, JavaElementLabels.ALL_FULLY_QUALIFIED)));
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_getter_pattern, BasicElementLabels.getJavaElementName(fGetterName)));
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_setter_pattern, BasicElementLabels.getJavaElementName(fSetterName)));
	String visibility= JdtFlags.getVisibilityString(fVisibility);
	if ("".equals(visibility)) //$NON-NLS-1$
		visibility= RefactoringCoreMessages.SelfEncapsulateField_default_visibility;
	comment.addSetting(Messages.format(RefactoringCoreMessages.SelfEncapsulateField_visibility_pattern, visibility));
	if (fEncapsulateDeclaringClass)
		comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_use_accessors);
	else
		comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_do_not_use_accessors);
	if (fGenerateJavadoc)
		comment.addSetting(RefactoringCoreMessages.SelfEncapsulateField_generate_comments);
	final EncapsulateFieldDescriptor descriptor= RefactoringSignatureDescriptorFactory.createEncapsulateFieldDescriptor(project, description, comment.asString(), arguments, flags);
	arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, fField));
	arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
	arguments.put(ATTRIBUTE_INSERTION, new Integer(fInsertionIndex).toString());
	arguments.put(ATTRIBUTE_SETTER, fSetterName);
	arguments.put(ATTRIBUTE_GETTER, fGetterName);
	arguments.put(ATTRIBUTE_COMMENTS, Boolean.valueOf(fGenerateJavadoc).toString());
	arguments.put(ATTRIBUTE_DECLARING, Boolean.valueOf(fEncapsulateDeclaringClass).toString());
	final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, getName());
	TextChange[] changes= fChangeManager.getAllChanges();
	pm.beginTask(NO_NAME, changes.length);
	pm.setTaskName(RefactoringCoreMessages.SelfEncapsulateField_create_changes);
	for (int i= 0; i < changes.length; i++) {
		result.add(changes[i]);
		pm.worked(1);
	}
	pm.done();
	return result;
}
 
Example 14
Source File: RenameFieldProcessor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private RefactoringStatus createChanges(IProgressMonitor pm) throws CoreException {
	pm.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 10);
	RefactoringStatus result= new RefactoringStatus();
	if (!fIsComposite)
		fChangeManager.clear();

	// Delegate creation requires ASTRewrite which
	// creates a new change -> do this first.
	if (fDelegateUpdating)
		result.merge(addDelegates());

	addDeclarationUpdate();

	if (fUpdateReferences) {
		addReferenceUpdates(new SubProgressMonitor(pm, 1));
		result.merge(analyzeRenameChanges(new SubProgressMonitor(pm, 2)));
		if (result.hasFatalError())
			return result;
	} else {
		pm.worked(3);
	}

	if (getGetter() != null && fRenameGetter) {
		addGetterOccurrences(new SubProgressMonitor(pm, 1), result);
	} else {
		pm.worked(1);
	}

	if (getSetter() != null && fRenameSetter) {
		addSetterOccurrences(new SubProgressMonitor(pm, 1), result);
	} else {
		pm.worked(1);
	}

	if (fUpdateTextualMatches) {
		addTextMatches(new SubProgressMonitor(pm, 5));
	} else {
		pm.worked(5);
	}
	pm.done();
	return result;
}
 
Example 15
Source File: Html2Xliff.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Builds the tables.
 * @param iniFile
 *            the ini file
 * @throws SAXException
 *             the SAX exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws ParserConfigurationException
 *             the parser configuration exception
 */
private void buildTables(String iniFile, IProgressMonitor monitor) throws SAXException, IOException,
		ParserConfigurationException {

	SAXBuilder builder = new SAXBuilder();
	Catalogue cat = new Catalogue(catalogue);
	builder.setEntityResolver(cat);
	Document doc = builder.build(iniFile);
	Element root = doc.getRootElement();
	List<Element> tags = root.getChildren("tag"); //$NON-NLS-1$

	startsSegment = new Hashtable<String, String>();
	translatableAttributes = new Hashtable<String, Vector<String>>();
	entities = new Hashtable<String, String>();
	ctypes = new Hashtable<String, String>();
	keepFormating = new Hashtable<String, String>();

	int size = tags.size();
	monitor.beginTask(Messages.getString("html.Html2Xliff.task3"), size);
	monitor.subTask("");
	Iterator<Element> i = tags.iterator();
	while (i.hasNext()) {
		if (monitor.isCanceled()) {
			// 用户取消操作
			throw new OperationCanceledException(Messages.getString("html.cancel"));
		}
		monitor.worked(1);
		Element t = i.next();
		if (t.getAttributeValue("hard-break", "inline").equals("segment")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			startsSegment.put(t.getText(), "yes"); //$NON-NLS-1$
		}
		if (t.getAttributeValue("keep-format", "no").equals("yes")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
			keepFormating.put(t.getText(), "yes"); //$NON-NLS-1$
		}
		String attributes = t.getAttributeValue("attributes", ""); //$NON-NLS-1$ //$NON-NLS-2$
		if (!attributes.equals("")) { //$NON-NLS-1$
			StringTokenizer tokenizer = new StringTokenizer(attributes, ";"); //$NON-NLS-1$
			int count = tokenizer.countTokens();
			Vector<String> v = new Vector<String>(count);
			for (int j = 0; j < count; j++) {
				v.add(tokenizer.nextToken());
			}
			translatableAttributes.put(t.getText(), v);
		}
		String ctype = t.getAttributeValue("ctype", ""); //$NON-NLS-1$ //$NON-NLS-2$
		if (!ctype.equals("")) { //$NON-NLS-1$
			ctypes.put(t.getText(), ctype);
		}
		t = null;
	}
	tags = null;

	List<Element> ents = root.getChildren("entity"); //$NON-NLS-1$
	Iterator<Element> it = ents.iterator();
	while (it.hasNext()) {
		Element e = it.next();
		entities.put("&" + e.getAttributeValue("name") + ";", e.getText()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}

	root = null;
	doc = null;
	builder = null;
	monitor.done();
}
 
Example 16
Source File: LoopNodesImportProgressDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings( "unchecked" )
private String[] doScan( IProgressMonitor monitor ) throws Exception {
  monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ScanningFile",
      filename ), 1 );

  SAXReader reader = XMLParserFactoryProducer.getSAXReader( null );
  monitor.worked( 1 );
  if ( monitor.isCanceled() ) {
    return null;
  }
  // Validate XML against specified schema?
  if ( meta.isValidating() ) {
    reader.setValidation( true );
    reader.setFeature( "http://apache.org/xml/features/validation/schema", true );
  } else {
    // Ignore DTD
    reader.setEntityResolver( new IgnoreDTDEntityResolver() );
  }
  monitor.worked( 1 );
  monitor
      .beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ReadingDocument" ), 1 );
  if ( monitor.isCanceled() ) {
    return null;
  }
  InputStream is = null;
  try {
    Document document = null;
    if ( !Utils.isEmpty( filename ) ) {
      is = KettleVFS.getInputStream( filename );
      document = reader.read( is, encoding );
    } else {
      if ( !Utils.isEmpty( xml ) ) {
        document = reader.read( new StringReader( xml ) );
      } else {
        document = reader.read( new URL( url ) );
      }
    }
    monitor.worked( 1 );
    monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.DocumentOpened" ),
        1 );
    monitor.worked( 1 );
    monitor.beginTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.ReadingNode" ), 1 );

    if ( monitor.isCanceled() ) {
      return null;
    }
    List<Node> nodes = document.selectNodes( document.getRootElement().getName() );
    monitor.worked( 1 );
    monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes" ) );

    if ( monitor.isCanceled() ) {
      return null;
    }
    for ( Node node : nodes ) {
      if ( monitor.isCanceled() ) {
        return null;
      }
      if ( !listpath.contains( node.getPath() ) ) {
        nr++;
        monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.FetchNodes",
            String.valueOf( nr ) ) );
        monitor.subTask( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.AddingNode", node
            .getPath() ) );
        listpath.add( node.getPath() );
        addLoopXPath( node, monitor );
      }
    }
    monitor.worked( 1 );
  } finally {
    try {
      if ( is != null ) {
        is.close();
      }
    } catch ( Exception e ) { /* Ignore */
    }
  }
  String[] list_xpath = listpath.toArray( new String[listpath.size()] );

  monitor.setTaskName( BaseMessages.getString( PKG, "GetXMLDateLoopNodesImportProgressDialog.Task.NodesReturned" ) );

  monitor.done();

  return list_xpath;

}
 
Example 17
Source File: BirtFacetInstallDelegate.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Invoke "INSTALL" event for project facet
 * 
 * @see org.eclipse.wst.common.project.facet.core.IDelegate#execute(org.eclipse.core.resources.IProject,
 *      org.eclipse.wst.common.project.facet.core.IProjectFacetVersion,
 *      java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
 */
public void execute( IProject project, IProjectFacetVersion fv,
		Object config, IProgressMonitor monitor ) throws CoreException
{
	monitor.beginTask( "", 4 ); //$NON-NLS-1$

	try
	{
		IDataModel facetDataModel = (IDataModel) config;
		IDataModel masterDataModel = (IDataModel) facetDataModel
				.getProperty( FacetInstallDataModelProvider.MASTER_PROJECT_DM );

		IPath destPath = null;
		// get web content folder
		if ( masterDataModel != null )
		{
			String configFolder = BirtWizardUtil
					.getConfigFolder( masterDataModel );

			if ( configFolder != null )
			{
				IFolder folder = BirtWizardUtil.getFolder( project, configFolder );
				if ( folder != null )
					destPath = folder.getFullPath( );
			}
		}
		else
		{
			destPath = BirtWizardUtil.getWebContentPath( project );
		}

		if ( destPath == null )
		{
			String message = BirtWTPMessages.BIRTErrors_wrong_webcontent;
			Logger.log( Logger.ERROR, message );
			throw BirtCoreException.getException( message, null );
		}			
		
		Map birtProperties = (Map) facetDataModel
				.getProperty( BirtFacetInstallDataModelProvider.BIRT_CONFIG );

		monitor.worked( 1 );

		// process BIRT Configuration
		preConfiguration( project, birtProperties, destPath.toFile( ).getName( ), monitor );

		monitor.worked( 1 );

		processConfiguration( project, birtProperties, monitor );

		monitor.worked( 1 );
		
		// import birt runtime componenet
		BirtWizardUtil.doImports( project, null, destPath, monitor,
				new SimpleImportOverwriteQuery( ) );

		monitor.worked( 1 );
	}
	finally
	{
		monitor.done( );
	}
}
 
Example 18
Source File: ImportRTFToXLIFF.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses the group.
 * @param group
 *            the group
 * @return the string
 */
private String parseGroup(String group, IProgressMonitor monitor) {
	int size = group.length();
	// 如果 size 大于 10000,则把总任务数按比例缩小 100 倍;如果 size 大于 100000,则把总任务数按比例缩小 1000
	// 倍。
	int scale = 1;
	if (size > 100000) {
		scale = 1000;
	} else if (size > 10000) {
		scale = 100;
	}
	int totalTask = size / scale;
	monitor.beginTask(Messages.getString(Messages.IMPORTRTFTOXLIFF_JOBTITLE_6), totalTask);
	Stack<String> localStack = new Stack<String>();
	String buff = ""; //$NON-NLS-1$
	int count = 0;
	for (int i = 0; i < group.length(); i++) {
		// 是否取消操作
		if (monitor.isCanceled()) {
			throw new OperationCanceledException();
		}
		char c = group.charAt(i);
		if (c == '{') {
			localStack.push(buff);
			buff = ""; //$NON-NLS-1$
		}
		buff = buff + c;
		if (c == '}') {
			String clean = cleanGroup(buff);
			buff = localStack.pop();
			if (buff.matches(".*\\\\[a-zA-Z]+") && clean.matches("[a-zA-z0-9].*")) { //$NON-NLS-1$ //$NON-NLS-2$
				buff = buff + " "; //$NON-NLS-1$
			}
			if (buff.matches(".*\\\\[a-zA-Z]+[0-9]+") && clean.matches("[0-9].*")) { //$NON-NLS-1$ //$NON-NLS-2$
				buff = buff + " "; //$NON-NLS-1$
			}
			buff = buff + clean;
		}
		count++;
		int temp = count / scale;
		count %= scale;
		if (temp > 0) {
			monitor.worked(temp);
		}
	}
	monitor.done();
	return buff;
}
 
Example 19
Source File: CommonPresentationReconciler.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected TextPresentation createPresentation(IRegion damage, IDocument document, IProgressMonitor monitor)
{
	try
	{
		int damageOffset = damage.getOffset();
		int damageLength = damage.getLength();
		if (damageOffset + damageLength > document.getLength())
		{
			int adjustedLength = document.getLength() - damageOffset;
			synchronized (this)
			{
				delayedRegions.remove(new Region(document.getLength(), damageLength - adjustedLength));
			}
			if (adjustedLength <= 0)
			{
				return null;
			}
			damageLength = adjustedLength;
		}
		TextPresentation presentation = new TextPresentation(damage, iterationPartitionLimit * 5);
		ITypedRegion[] partitioning = TextUtilities.computePartitioning(document, getDocumentPartitioning(),
				damageOffset, damageLength, false);
		if (partitioning.length == 0)
		{
			return presentation;
		}
		int limit = Math.min(iterationPartitionLimit, partitioning.length);
		int processingLength = partitioning[limit - 1].getOffset() + partitioning[limit - 1].getLength()
				- damageOffset;
		if (EclipseUtil.showSystemJobs())
		{
			monitor.subTask(MessageFormat.format(
					"processing region at offset {0}, length {1} in document of length {2}", damageOffset, //$NON-NLS-1$
					processingLength, document.getLength()));
		}

		for (int i = 0; i < limit; ++i)
		{
			ITypedRegion r = partitioning[i];
			IPresentationRepairer repairer = getRepairer(r.getType());
			if (monitor.isCanceled())
			{
				return null;
			}
			if (repairer != null)
			{
				repairer.createPresentation(presentation, r);
			}
			monitor.worked(r.getLength());
		}

		synchronized (this)
		{
			delayedRegions.remove(new Region(damageOffset, processingLength));
			if (limit < partitioning.length)
			{
				int offset = partitioning[limit].getOffset();
				delayedRegions.append(new Region(offset, damageOffset + damageLength - offset));
			}
		}
		return presentation;
	}
	catch (BadLocationException e)
	{
		return null;
	}
}
 
Example 20
Source File: SVNMergeUtil.java    From MergeProcessor with Apache License 2.0 4 votes vote down vote up
public static boolean merge(ProgressMonitorDialog pmd, IProgressMonitor monitor, SVNMergeUnit mergeUnit)
		throws SvnClientException {
	LogUtil.entering(pmd, monitor, mergeUnit);

	String taskName = String.format(Messages.MergeProcessorUtil_Process_TaskName, mergeUnit.getRepository(),
			mergeUnit.getRevisionInfo(), mergeUnit.getBranchSource(), mergeUnit.getBranchTarget());
	monitor.beginTask(taskName, 9);

	boolean cancel = false;
	final ISvnClient client = E4CompatibilityUtil.getApplicationContext().get(ISvnClient.class);

	if (!cancel) {
		monitor.subTask("copyRemoteToLocal"); //$NON-NLS-1$
		cancel = copyRemoteToLocal(mergeUnit);
		monitor.worked(1);
		if (monitor.isCanceled()) {
			LOGGER.fine("User cancelled after 'copyRemoteToLocal'."); //$NON-NLS-1$
			cancel = true;
		}
	}

	if (!cancel) {
		monitor.subTask("buildMinimalWorkingCopy"); //$NON-NLS-1$
		cancel = buildMinimalSVNWorkingCopy((SVNMergeUnit) mergeUnit, client);
		monitor.worked(1);
		if (monitor.isCanceled()) {
			LOGGER.fine("User cancelled after 'buildMinimalWorkingCopy'."); //$NON-NLS-1$
			cancel = true;
		}
	}

	if (!cancel) {
		monitor.subTask("mergeChangesIntoWorkingCopy"); //$NON-NLS-1$
		cancel = mergeChangesIntoWorkingCopy(mergeUnit, client);
		monitor.worked(1);
		if (monitor.isCanceled()) {
			LOGGER.fine("User cancelled after 'mergeChangesIntoWorkingCopy'."); //$NON-NLS-1$
			cancel = true;
		}
	}

	if (!cancel) {
		monitor.subTask("checkIsCommittable"); //$NON-NLS-1$
		cancel = checkIsCommittable(mergeUnit, client);
		monitor.worked(1);
		if (monitor.isCanceled()) {
			LOGGER.fine("User cancelled after 'checkIsCommittable'."); //$NON-NLS-1$
			cancel = true;
		}
	}

	if (!cancel) {
		monitor.subTask("commitChanges"); //$NON-NLS-1$

		// can't cancel after commit
		pmd.setCancelable(false);

		cancel = commitChanges(mergeUnit, client);
		monitor.worked(1);
	}

	if (!cancel) {
		monitor.subTask("copyLocalToDone"); //$NON-NLS-1$
		cancel = copyLocalToDone(mergeUnit);
		monitor.worked(1);
	}

	if (cancel) {
		mergeUnit.setStatus(MergeUnitStatus.CANCELLED);
	}

	// delete the local merge file, even if cancelled.
	monitor.subTask("deleteLocal"); //$NON-NLS-1$
	deleteLocal(mergeUnit);
	monitor.worked(1);
	return LogUtil.exiting(cancel);
}