List of usage examples for org.eclipse.jface.wizard ProgressMonitorPart isCanceled
@Override
public boolean isCanceled()
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 w ww . j a v a2 s. c o m*/ 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 {/*from w ww.j a v a 2s. c om*/ 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"); } }