List of usage examples for org.eclipse.jface.wizard ProgressMonitorPart beginTask
@Override
public void beginTask(String name, int totalWork)
From source file:it.eng.spagobi.studio.core.services.modelTemplate.RefreshModelService.java
License:Mozilla Public License
public void refreshModelTemplate() { IStructuredSelection sel = (IStructuredSelection) selection; // go on only if you selected a document (a file) Object objSel = sel.toList().get(0); File fileSel = null;/*from www .j av a 2 s .c om*/ try { fileSel = (File) objSel; projectName = fileSel.getProject().getName(); modelName = fileSel.getName(); } catch (Exception e) { logger.error("No file selected", e); MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Not a file", "You must select a file to refresh"); return; } logger.debug("get datamart.jar of model file name " + fileSel.getName()); EmfXmiSerializer emfXmiSerializer = new EmfXmiSerializer(); Model root = null; BusinessModel businessModel = null; try { root = emfXmiSerializer.deserialize(fileSel.getContents(true)); logger.debug("Model root is [{}] ", root); businessModel = root.getBusinessModels().get(0); logger.debug("model " + businessModel.getName()); } catch (Exception e) { logger.error("error in retrieving business model; try refreshing model folder ", e); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Warning", "error in retrieving business model: try refreshing model folder"); return; } final BusinessModel finalBusinessModel = businessModel; ProgressMonitorPart monitor; monitor = new ProgressMonitorPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null); logger.debug("Do the model template refresh, model with name " + modelName); final org.eclipse.core.internal.resources.File fileSel2 = fileSel; final NoDocumentException documentException = new NoDocumentException(); final NoActiveServerException noActiveServerException = new NoActiveServerException(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask("Template Refresh for model " + modelName, IProgressMonitor.UNKNOWN); // document associated, upload the template SpagoBIServerObjectsFactory spagoBIServerObjects = null; try { spagoBIServerObjects = new SpagoBIServerObjectsFactory(projectName); documentException.setNoDocument(false); Template mytemplate = spagoBIServerObjects.getServerDocuments() .downloadDatamartFile(finalBusinessModel.getName(), modelName); if (mytemplate == null) { logger.error("The download operation has returned a null object!"); documentException.setNoDocument(true); return; } template.setContent(mytemplate.getContent()); template.setFileName(mytemplate.getFileName()); overwriteTemplate(template, fileSel2); } catch (NoActiveServerException e1) { noActiveServerException.setNoServer(true); return; } catch (RemoteException re) { logger.error("Error comunicating with server", re); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error comunicating with server", "Error while uploading the template: missing comunication with server"); return; } catch (CoreException ec) { logger.error("Error in fie creation", ec); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error in file creation", "Error in file creation"); return; } monitor.done(); if (monitor.isCanceled()) logger.error("The long running operation was cancelled"); } }; ProgressMonitorDialog dialog = new ProgressMonitorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); try { dialog.run(true, true, op); } catch (InvocationTargetException e1) { logger.error("Error comunicating with server", e1); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "Missing comunication with server; check server definition and if service is avalaible"); dialog.close(); return; } catch (InterruptedException e1) { logger.error("Error comunicating with server"); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "Missing comunication with server; check server definition and if service is avalaible"); dialog.close(); return; } if (noActiveServerException.isNoServer()) { logger.error("No server is defined active"); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "No server is defined active"); return; } // check if document has been found (could have been deleted) if (documentException.isNoDocument() || template.getContent() == null) { logger.warn("Document no more present on server or no permission " + modelName); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error upload", "Document not retrieved; check it is still on server and you have enough permission to reach it. Make a new Upload."); return; } dialog.close(); String succesfullMessage = "Succesfully replaced with the last model template (" + modelName + ")"; logger.debug(succesfullMessage); MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Refresh succesfull", succesfullMessage); }
From source file:it.eng.spagobi.studio.core.services.template.RefreshTemplateService.java
License:Mozilla Public License
public void refreshTemplate() { SpagoBIDeployWizard sbindw = new SpagoBIDeployWizard(); IStructuredSelection sel = (IStructuredSelection) selection; // go on only if you selected a document (a file) Object objSel = sel.toList().get(0); org.eclipse.core.internal.resources.File fileSel = null; try {/* w w w. ja va 2 s . c o m*/ fileSel = (org.eclipse.core.internal.resources.File) objSel; projectName = fileSel.getProject().getName(); } catch (Exception e) { logger.error("No file selected", e); MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Not a file", "You must select a file to refresh"); return; } //if file has document metadata associated upload it, else call wizard String document_idString = null; String document_label = null; try { document_idString = fileSel.getPersistentProperty(SpagoBIStudioConstants.DOCUMENT_ID); document_label = fileSel.getPersistentProperty(SpagoBIStudioConstants.DOCUMENT_LABEL); } catch (CoreException e) { logger.error("Error in retrieving document Label", e); } //final Integer documentId=Integer.valueOf(document_idString); // IF File selected has already an id of document associated start the templater refresh, else throw an error if (document_idString != null) { ProgressMonitorPart monitor; monitor = new ProgressMonitorPart(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), null); logger.debug("Metadata found: do the template refresh, document with id " + document_idString); final Integer idInteger = Integer.valueOf(document_idString); final String label2 = document_label; final org.eclipse.core.internal.resources.File fileSel2 = fileSel; final NoDocumentException documentException = new NoDocumentException(); final NoActiveServerException noActiveServerException = new NoActiveServerException(); IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { monitor.beginTask("Template Refresh for document " + label2, IProgressMonitor.UNKNOWN); // document associated, upload the template SpagoBIServerObjectsFactory spagoBIServerObjects = null; try { spagoBIServerObjects = new SpagoBIServerObjectsFactory(projectName); // check document still exists document = spagoBIServerObjects.getServerDocuments().getDocumentByLabel(label2); if (document == null) { documentException.setNoDocument(true); return; } else { documentException.setNoDocument(false); Template mytemplate = spagoBIServerObjects.getServerDocuments() .downloadTemplate(idInteger); template.setContent(mytemplate.getContent()); template.setFileName(mytemplate.getFileName()); String fileName = mytemplate.getFileName(); String previousExtension = null; int index = fileName.indexOf('.'); if (index != -1) { previousExtension = fileName.substring(index + 1, fileName.length()); } // get documents metadata String fileExtension = recoverFileExtension(document, idInteger, spagoBIServerObjects, previousExtension); overwriteTemplate(template, fileSel2, fileExtension, spagoBIServerObjects); } } // catch (NotAllowedOperationException e) { // logger.error("Not Allowed Operation",e); // MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // "Error upload", "Error while uploading the template: not allowed operation"); // return; // } catch (NoActiveServerException e1) { noActiveServerException.setNoServer(true); return; } catch (RemoteException e) { logger.error("Error comunicating with server", e); logger.error("Error comunicating with server", e); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error comunicating with server", "Error while uploading the template: missing comunication with server"); return; } catch (CoreException e) { logger.error("Error in fie creation", e); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error in file creation", "Error in file creation"); return; } monitor.done(); if (monitor.isCanceled()) logger.error("The long running operation was cancelled"); } }; ProgressMonitorDialog dialog = new ProgressMonitorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); try { dialog.run(true, true, op); } catch (InvocationTargetException e1) { logger.error("Error comunicating with server", e1); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "Missing comunication with server; check server definition and if service is avalaible"); dialog.close(); return; } catch (InterruptedException e1) { logger.error("Error comunicating with server"); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "Missing comunication with server; check server definition and if service is avalaible"); dialog.close(); return; } if (noActiveServerException.isNoServer()) { logger.error("No server is defined active"); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "No server is defined active"); return; } // check if document has been found (could have been deleted) or if the template was already present somewhere else if (documentException.isNoDocument() || template.getContent() == null) { logger.warn("Document no more present on server or no permission " + document_label); MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error upload", "Document not retrieved; check it is still on server and you have enough permission to reach it. Make a new Deploy."); return; } if (alreadyPresentException != null && alreadyPresentException.isAlreadyPresent()) { logger.warn("Template ealready present in project workspace: " + newTemplateName); MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error", "File " + alreadyPresentException.getFilePath() + " already exists in your project: to download it againg you must first delete the existing one"); return; } dialog.close(); String succesfullMessage = "Succesfully replaced with the last template version of the associated document " + document_label; if (newTemplateName != null) { succesfullMessage += ": template file has changed its name; new one is " + newTemplateName; } logger.debug(succesfullMessage); MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Refresh succesfull", succesfullMessage); } else { logger.warn("No document associated "); MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "No document warning", "The file selected has no document associated, to the deploy first"); } }
From source file:org.eclipse.wst.internet.cache.internal.LicenseAcceptanceDialog.java
License:Open Source License
/** * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) *///from w w w . j a va 2 s . c o m protected Control createContents(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); composite.setLayout(layout); GridData gd = new GridData(SWT.FILL); gd.widthHint = 500; composite.setLayoutData(gd); // Display a statement about the license. Label licenseText1 = new Label(composite, SWT.NONE); licenseText1.setText(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT1); Label urlText = new Label(composite, SWT.WRAP); gd = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1); urlText.setLayoutData(gd); urlText.setText(url); new Label(composite, SWT.NONE); // Spacing label. Label licenseText2 = new Label(composite, SWT.WRAP); gd = new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1); licenseText2.setLayoutData(gd); // Display the license in a browser. try { final Composite licenseTextComposite = new Composite(composite, SWT.NONE); final StackLayout stackLayout = new StackLayout(); licenseTextComposite.setLayout(stackLayout); gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = 400; licenseTextComposite.setLayoutData(gd); // Create the loading progress monitor composite and part. Composite monitorComposite = new Composite(licenseTextComposite, SWT.NONE); monitorComposite.setLayout(new GridLayout()); gd = new GridData(SWT.FILL, SWT.FILL, true, true); gd.heightHint = 400; monitorComposite.setLayoutData(gd); final ProgressMonitorPart monitor = new ProgressMonitorPart(monitorComposite, new GridLayout()); gd = new GridData(SWT.FILL, SWT.BOTTOM, true, true); monitor.setLayoutData(gd); monitor.beginTask(CacheMessages._UI_LOADING_LICENSE, 100); stackLayout.topControl = monitorComposite; // Create the browser. final Browser browser = new Browser(licenseTextComposite, SWT.BORDER); gd = new GridData(SWT.FILL, SWT.FILL, true, true); //gd.heightHint = 400; // It's important that the license URL is set even if we read // the contents of the license file ourselves (see below) as // otherwise the progress monitor will not be called on certain // linux systems with certain browsers. browser.setUrl(licenseURL); // The browser widget has problems loading files stored in jars // so we read from the jar and set the browser text ourselves. // See bug 154721. if (licenseURL.startsWith("jar:")) { InputStream licenseStream = null; InputStreamReader isreader = null; BufferedReader breader = null; try { URL browserURL = new URL(licenseURL); licenseStream = browserURL.openStream(); isreader = new InputStreamReader(licenseStream); breader = new BufferedReader(isreader); String str; StringBuffer sb = new StringBuffer(); while ((str = breader.readLine()) != null) { sb.append(str); } browser.setText(sb.toString()); } finally { if (licenseStream != null) { licenseStream.close(); } if (isreader != null) { isreader.close(); } if (breader != null) { breader.close(); } } } browser.setLayoutData(gd); browser.addProgressListener(new ProgressListener() { /* (non-Javadoc) * @see org.eclipse.swt.browser.ProgressListener#changed(org.eclipse.swt.browser.ProgressEvent) */ public void changed(ProgressEvent event) { if (event.total != 0) { monitor.internalWorked(event.current * 100 / event.total); } } /* (non-Javadoc) * @see org.eclipse.swt.browser.ProgressListener#completed(org.eclipse.swt.browser.ProgressEvent) */ public void completed(ProgressEvent event) { monitor.done(); stackLayout.topControl = browser; agreeButton.setEnabled(true); licenseTextComposite.layout(); } }); licenseText2.setText(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT2); } catch (Exception e) { // The browser throws an exception on platforms that do not support it. // In this case we need to create an external browser. try { CachePlugin.getDefault().getWorkbench().getBrowserSupport().getExternalBrowser() .openURL(new URL(licenseURL)); licenseText2.setText(CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT2_NO_INTERNAL); } catch (Exception ex) { // In this case the license cannot be display. Inform the user of this and give them the license location. licenseText2.setText(MessageFormat.format( CacheMessages._UI_CACHE_DIALOG_LICENSE_STATEMENT2_NO_BROWSER, new Object[] { licenseURL })); } } createButtonBar(composite); return composite; }