Java Code Examples for org.eclipse.emf.common.util.Monitor#worked()
The following examples show how to use
org.eclipse.emf.common.util.Monitor#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: M2DocLauncher.java From M2Doc with Eclipse Public License 1.0 | 6 votes |
/** * Launches the given {@link Generation}. * * @param generation * the {@link Generation} to launch * @param monitor * the {@link Monitor} */ private void launchGenerationConfiguration(Generation generation, final Monitor monitor) { try { System.out.println("Input: " + generation.eResource().getURI()); List<URI> generated = GenconfUtils.generate(generation, M2DocPlugin.getClassProvider(), monitor); for (URI uri : generated) { System.out.println("Output: " + uri.toString()); } monitor.worked(1); } catch (DocumentGenerationException | IOException | DocumentParserException e) { final String message = String.format(ERROR_LAUNCHING_GENCONF, generation.eResource().getURI().toString(), e.getMessage()); M2DocLauncherPlugin.INSTANCE .log(new Status(IStatus.ERROR, M2DocLauncherPlugin.INSTANCE.getSymbolicName(), message, e)); } }
Example 2
Source File: M2DocUtils.java From M2Doc with Eclipse Public License 1.0 | 4 votes |
/** * Parses a template document and returns the {@link DocumentTemplate} resulting from * this parsing. * * @param uriConverter * the {@link URIConverter uri converter} to use. * @param templateURI * URI for the template, used when external links (images, includes) have to be resolved * @param queryEnvironment * the {@link IQueryEnvironment} * @param classProvider * the {@link IClassProvider} to use for service Loading * @param monitor * used to track the progress will generating * @return the {@link DocumentTemplate} resulting from parsing the specified * document * @throws DocumentParserException * if a problem occurs while parsing the document. */ @SuppressWarnings("resource") public static DocumentTemplate parse(URIConverter uriConverter, URI templateURI, IQueryEnvironment queryEnvironment, IClassProvider classProvider, Monitor monitor) throws DocumentParserException { final DocumentTemplate result = (DocumentTemplate) EcoreUtil.create(TemplatePackage.Literals.DOCUMENT_TEMPLATE); final ResourceImpl r = new ResourceImpl(templateURI); try { monitor.beginTask("Parsing " + templateURI, TOTAL_PARSE_MONITOR_WORK); monitor.subTask("Loading template"); // resources are closed in DocumentTemplate.close() final InputStream is = uriConverter.createInputStream(templateURI); final OPCPackage oPackage = OPCPackage.open(is); final XWPFDocument document = new XWPFDocument(oPackage); nextSubTask(monitor, LOAD_TEMPLATE_MONITOR_WORK, "Parsing template custom properties"); final List<TemplateValidationMessage> messages = parseTemplateCustomProperties(queryEnvironment, classProvider, document); r.getContents().add(result); nextSubTask(monitor, PARSE_TEMPLATE_CUSTOM_PROPERTIES_MONITOR_WORK, "Parsing template body"); final int unitOfWork = PARSE_TEMPLATE_MONITOR_WORK / (1 + document.getFooterList().size() + document.getHeaderList().size()); final M2DocParser parser = new M2DocParser(document, queryEnvironment); final Block documentBody = parser.parseBlock(result.getTemplates(), TokenType.EOF); for (TemplateValidationMessage validationMessage : messages) { documentBody.getValidationMessages().add(validationMessage); } result.setBody(documentBody); result.setInputStream(is); result.setOpcPackage(oPackage); result.setDocument(document); nextSubTask(monitor, unitOfWork, "Parsing template footers"); for (XWPFFooter footer : document.getFooterList()) { final M2DocParser footerParser = new M2DocParser(footer, queryEnvironment); result.getFooters().add(footerParser.parseBlock(null, TokenType.EOF)); monitor.worked(unitOfWork); } nextSubTask(monitor, 0, "Parsing template headers"); for (XWPFHeader header : document.getHeaderList()) { final M2DocParser headerParser = new M2DocParser(header, queryEnvironment); result.getHeaders().add(headerParser.parseBlock(null, TokenType.EOF)); monitor.worked(unitOfWork); } } catch (IOException e) { throw new DocumentParserException("Unable to open " + templateURI, e); } catch (InvalidFormatException e1) { throw new DocumentParserException("Invalid .docx format " + templateURI, e1); } finally { monitor.done(); } return result; }
Example 3
Source File: M2DocValidator.java From M2Doc with Eclipse Public License 1.0 | 3 votes |
/** * Progresses the given amount of work on the given {@link Monitor}. * * @param monitor * the {@link Monitor} * @param work * the amount of work */ private void worked(Monitor monitor, int work) { if (monitor.isCanceled()) { throw new CancellationException("Canceled by user"); } monitor.worked(work); }
Example 4
Source File: M2DocEvaluator.java From M2Doc with Eclipse Public License 1.0 | 3 votes |
/** * Progresses the given amount of work on the given {@link Monitor}. * * @param progressMonitor * the {@link Monitor} * @param work * the amount of work */ private void worked(Monitor progressMonitor, int work) { if (progressMonitor.isCanceled()) { throw new CancellationException("Canceled by user"); } progressMonitor.worked(work); }
Example 5
Source File: M2DocUtils.java From M2Doc with Eclipse Public License 1.0 | 3 votes |
/** * Starts next sub task on the given {@link Monitor}. * * @param monitor * the {@link Monitor} * @param previousTaskDone * the work done in the previous task * @param nextSubTaskName * the next sub task name */ private static void nextSubTask(Monitor monitor, int previousTaskDone, String nextSubTaskName) { if (monitor.isCanceled()) { throw new CancellationException("Canceled by user"); } monitor.worked(previousTaskDone); monitor.subTask(nextSubTaskName); }