Example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run

List of usage examples for org.eclipse.jface.dialogs ProgressMonitorDialog run

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs ProgressMonitorDialog run.

Prototype

@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException 

Source Link

Document

This implementation of IRunnableContext#run(boolean, boolean, IRunnableWithProgress) runs the given IRunnableWithProgress using the progress monitor for this progress dialog and blocks until the runnable has been run, regardless of the value of fork.

Usage

From source file:it.eng.spagobi.studio.core.services.template.DeployTemplateService.java

License:Mozilla Public License

/** if document has meadata associated do the automated deploy
 * //from   ww  w. j  a  va  2s. com
 * @return if automated eply has been done
 */
public boolean doAutomaticDeploy() {
    logger.debug("IN");
    IStructuredSelection sel = (IStructuredSelection) selection;

    // go on only if you selected a document
    Object objSel = sel.toList().get(0);
    org.eclipse.core.internal.resources.File fileSel = null;
    fileSel = (org.eclipse.core.internal.resources.File) objSel;
    projectname = fileSel.getProject().getName();

    //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);
    }

    // IF File selected has already and id of document associated do the upload wiyhout asking further informations
    boolean newDeploy = false;
    if (document_idString != null) {
        logger.debug("Template already associated to document " + 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("Deploying to document " + label2, IProgressMonitor.UNKNOWN);

                if (projectname == null) {
                    projectname = fileSel2.getProject().getName();
                }

                try {
                    // document associated, upload the template

                    SpagoBIServerObjectsFactory spagoBIServerObjects = new SpagoBIServerObjectsFactory(
                            projectname);

                    URI uri = fileSel2.getLocationURI();

                    File fileJava = new File(uri.getPath());
                    FileDataSource fileDataSource = new FileDataSource(fileJava);
                    DataHandler dataHandler = new DataHandler(fileDataSource);
                    Template template = new Template();
                    template.setFileName(fileSel2.getName());
                    template.setContent(dataHandler);

                    // check document still exists
                    //Document doc=spagoBIServerObjects.getServerDocuments().getDocumentById(idInteger);
                    Document doc = spagoBIServerObjects.getServerDocuments().getDocumentByLabel(label2);
                    if (doc == null) {
                        documentException.setNoDocument(true);
                        logger.warn(
                                "Document not retrieved; check it is still on server and you have enough permission to reach it"
                                        + idInteger);
                        return;
                    } else {
                        documentException.setNoDocument(false);

                        // **** Label defined inside template (Ext Chart case) ***
                        // in thecaseof an extChart also te dataset must be re-assigned because it could have been changed
                        String labelInsideXml = null;
                        try {
                            labelInsideXml = fileSel2
                                    .getPersistentProperty(SpagoBIStudioConstants.DATASET_LABEL_INSIDE);
                        } catch (CoreException e) {
                            logger.warn(
                                    "Errorin finding dataset label nto template, go on anyway using server one");
                        }

                        IDataSet found = null;
                        if (labelInsideXml != null) { // EXT CHART CASE
                            logger.debug("Set dataset document on server to " + labelInsideXml);
                            IDataSet[] datasets = spagoBIServerObjects.getServerDatasets().getDataSetList();
                            // get the id of the new datset
                            for (int i = 0; i < datasets.length && found == null; i++) {
                                if (datasets[i].getLabel().equals(labelInsideXml)) {
                                    found = datasets[i];
                                }
                            }
                            if (found != null) {
                                Integer id = found.getId();
                                doc.setDataSetId(id);
                                logger.debug("update document with new dataset reference");
                            } else {
                                logger.error("dataset " + labelInsideXml
                                        + " not found in server. delete dataset association");
                                doc.setDataSetId(null);
                            }
                            spagoBIServerObjects.getServerDocuments().saveNewDocument(doc, template, null);

                        } else { // OTHER DOCUMENTS CASE
                            spagoBIServerObjects.getServerDocuments().uploadTemplate(idInteger, template);
                        }

                        // ALl documents case

                        // in case of dataset definition changed the dataset label as file metadata must be changed
                        if (found != null) {
                            try {
                                fileSel2.setPersistentProperty(SpagoBIStudioConstants.DATASET_ID,
                                        found.getId().toString());
                                fileSel2.setPersistentProperty(SpagoBIStudioConstants.DATASET_LABEL,
                                        found.getLabel());
                                fileSel2.setPersistentProperty(SpagoBIStudioConstants.DATASET_NAME,
                                        found.getName());
                                fileSel2.setPersistentProperty(SpagoBIStudioConstants.DATASET_DESCRIPTION,
                                        found.getDescription());
                            } catch (CoreException e) {
                                logger.error(
                                        "Errorn updating file metadata about new dataset associated: go on anyway");
                            }
                        }

                    }
                }

                catch (NoActiveServerException e1) {
                    // no active server found 
                    noActiveServerException.setNoServer(true);
                    return;
                } catch (RemoteException 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;
                }

                monitor.done();
                if (monitor.isCanceled())
                    logger.error("Operation not ended",
                            new InterruptedException("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 false;
        } catch (InterruptedException 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 false;
        }
        if (documentException.isNoDocument()) {
            logger.error(
                    "Document not retrieved; check it is still on server and you have enough permission to reach it");
            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");
            newDeploy = true;
            sbdw.setNewDeployFromOld(true);
        }
        if (noActiveServerException.isNoServer()) {
            logger.error("No server is defined active");
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                    "No server is defined active");
            return false;
        }

        dialog.close();
        if (!newDeploy) {
            MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "Deploy succesfull",
                    "Deployed to the associated document " + document_label + " succesfull");
            logger.debug("Deployed to the associated document " + document_label + " succesfull");
        }
    } else {
        newDeploy = true;
    }

    if (newDeploy) {
        logger.debug("deploy a new Document: start wizard");
        // init wizard
        sbdw.init(PlatformUI.getWorkbench(), sel);
        // Create the wizard dialog
        WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                sbdw);

        //         {
        //            @Override
        //            protected void configureShell(Shell newShell) {
        //               super.configureShell(newShell);
        //               newShell.setSize(1300, 600);
        //            }
        //         };

        // Open the wizard dialog
        dialog.open();
    }
    logger.debug("OUT");
    return true;

}

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 ww .jav  a2  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:it.eng.spagobi.studio.core.wizards.deployDatasetWizard.SpagoBIDeployDatasetWizardFormPage.java

License:Mozilla Public License

/**
 *  fill the value//from  w  w  w .ja  v  a2s .  c o  m
 */
public void fillValues() {
    logger.debug("IN");
    IFile fileSel = (IFile) selection.toList().get(0);
    String queryStr = DeployDatasetService.getMetaQuery(fileSel);
    logger.debug("Query in file is " + queryStr);
    queryStr = queryStr != null ? queryStr : "";
    //      queryText.setText(queryStr);
    query = queryStr;

    // first of all get info from server      
    final SpagoBIServerObjectsFactory proxyObjects;
    SDKProxyFactory proxyFactory = null;
    try {
        proxyObjects = new SpagoBIServerObjectsFactory(projectName);
    } catch (NoActiveServerException e1) {
        logger.error("No active server found", e1);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "No active server found");
        return;
    }

    // progress monitor to recover datasource information
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Deploy a new dataset: retrieve data sources ", IProgressMonitor.UNKNOWN);

            try {

                datasourceList = proxyObjects.getServerDataSources().getDataSourceList();
                logger.debug("datasources retrieved");
                domainList = proxyObjects.getServerDomains().getDomainsListByDomainCd("CATEGORY_TYPE");
                logger.debug("domains retrieved");

            } catch (Exception e) {
                logger.error("No comunication with SpagoBI server", e);
                MessageDialog.openError(getShell(), "No comunication with server",
                        "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
                return;
            }
            monitor.done();
            if (monitor.isCanceled())
                logger.error("Operation not ended",
                        new InterruptedException("The long running operation was cancelled"));
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e1) {
        logger.error(
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible",
                e1);
        dialog.close();
        MessageDialog.openError(getShell(), "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    } catch (InterruptedException e1) {
        logger.error("No comunication with SpagoBI server", e1);
        dialog.close();
        MessageDialog.openError(getShell(), "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    }
    dialog.close();

    dataSourceLabelIdMap = new HashMap<String, Integer>();
    String[] datasourceLabels = new String[datasourceList.length];
    for (int i = 0; i < datasourceLabels.length; i++) {
        DataSource dataSource = datasourceList[i];
        logger.debug("Datasource " + dataSource.getName());
        datasourceLabels[i] = dataSource.getLabel();
        dataSourceLabelIdMap.put(dataSource.getLabel(), dataSource.getId());
    }
    Arrays.sort(datasourceLabels);
    dataSourceCombo.setItems(datasourceLabels);

    logger.debug("Datasources combo filled");

    domainsLabelIdMap = new HashMap<String, Integer>();
    String[] domainsLabels = new String[domainList.length];
    for (int i = 0; i < domainsLabels.length; i++) {
        Domain domain = domainList[i];
        logger.debug("Domain " + domain.getValueCd());
        domainsLabels[i] = domain.getValueCd();
        domainsLabelIdMap.put(domain.getValueCd(), domain.getValueId());
    }
    Arrays.sort(domainsLabels);
    categoryCombo.setItems(domainsLabels);

    publicCombo.add("Private");
    publicCombo.add("Public");
    publicCombo.select(0);
    logger.debug("OUT");

}

From source file:it.eng.spagobi.studio.core.wizards.deployOlapWizard.SpagoBIDeployOlapTemplateWizardFormPage.java

License:Mozilla Public License

/** Creates the wizard form
 * @see IDialogPage#createControl(Composite)
 */// w ww.j a  va 2s.c  om
public void createControl(Composite parent) {
    logger.debug("IN");
    Shell shell = parent.getShell();
    monitor = new ProgressMonitorPart(new Shell(), null);

    Object objSel = selection.toList().get(0);
    File fileSelected = (File) objSel;
    projectName = fileSelected.getProject().getName();

    final SpagoBIServerObjectsFactory proxyObjects;
    // first of all get info from server      
    SDKProxyFactory proxyFactory = null;
    try {
        proxyObjects = new SpagoBIServerObjectsFactory(projectName);

    } catch (NoActiveServerException e1) {
        logger.error("No active server found", e1);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "No active server found");
        return;
    }

    final NotAllowedOperationStudioException notAllowedOperationStudioException = new NotAllowedOperationStudioException();

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Deploy a new Document: ", IProgressMonitor.UNKNOWN);

            try {

                datasourceList = proxyObjects.getServerDataSources().getDataSourceList();

            } catch (Exception e) {
                if (e.getClass().toString()
                        .equalsIgnoreCase("class it.eng.spagobi.sdk.exceptions.NotAllowedOperationException")) {
                    logger.error("NotAllowed User Permission", e);
                    notAllowedOperationStudioException.setNotAllowed(true);
                } else {
                    logger.error("No comunication with SpagoBI server", e);
                    MessageDialog.openError(getShell(), "No comunication with server",
                            "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
                }
                return;
            }
            monitor.done();
            if (monitor.isCanceled())
                logger.error("The long running operation was cancelled");
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e1) {
        logger.error(
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible",
                e1);
        dialog.close();
        MessageDialog.openError(getShell(), "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    } catch (InterruptedException e1) {
        logger.error("No comunication with SpagoBI server", e1);
        dialog.close();
        MessageDialog.openError(getShell(), "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    }
    dialog.close();

    if (notAllowedOperationStudioException.isNotAllowed()) {
        logger.error("User has no permission to complete the operation");
        MessageDialog.openError(getShell(), "Error", "User has no permission to complete the operation");
        return;
    }

    /*
    FillLayout fl2=new FillLayout();
    fl2.type=SWT.HORIZONTAL;
    parent.setLayout(fl2);
    */

    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(1, false));
    Composite left = new Composite(main, SWT.BORDER);
    left.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    GridLayout gl = new GridLayout();
    int ncol = 2;
    gl.numColumns = 2;
    left.setLayout(gl);

    // *************** Left Layout **********************

    Label label_1 = new Label(left, SWT.NONE);
    label_1.setText("Name:");
    nameText = new Text(left, SWT.BORDER);
    GridData gd_nameText = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gd_nameText.widthHint = 146;
    nameText.setLayoutData(gd_nameText);
    nameText.setTextLimit(20);
    nameText.addListener(SWT.KeyUp, new Listener() {
        public void handleEvent(Event event) {
            //check if page is complete
            boolean complete = isPageComplete();
            if (complete) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });

    Label label_2 = new Label(left, SWT.NONE);
    label_2.setText("Description:");
    descriptionText = new Text(left, SWT.BORDER);
    descriptionText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    descriptionText.setTextLimit(SpagoBIStudioConstants.BIOBJECT_DESCRIPTION_LIMIT);

    typeLabel = BiObjectUtilities.getTypeFromExtension(fileSelected.getName());

    int indexPoint = fileSelected.getName().indexOf('.');
    String extension = "";
    if (indexPoint != -1) {
        extension = fileSelected.getName().substring(indexPoint + 1);
    }

    if (typeLabel == null) {
        logger.error("File " + fileSelected.getName() + " has unknown exstension");
        MessageDialog.openError(getShell(), "No type",
                "File " + fileSelected.getName() + " has unknown exstension");
        return;
    }

    // Select datasource
    Label label = new Label(left, SWT.NONE);
    label.setText("Datasource");

    String[] datasourceLabels = new String[datasourceList.length];
    dataSourceLabelIdMap = new HashMap<String, Integer>();

    for (int i = 0; i < datasourceLabels.length; i++) {
        DataSource dataSource = datasourceList[i];
        datasourceLabels[i] = dataSource.getLabel();
        dataSourceLabelIdMap.put(dataSource.getLabel(), dataSource.getId());
    }
    Arrays.sort(datasourceLabels);
    dataSourceCombo = new Combo(left, SWT.NONE | SWT.READ_ONLY);
    dataSourceCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    dataSourceCombo.setItems(datasourceLabels);

    setControl(left);

}

From source file:it.eng.spagobi.studio.core.wizards.deployWizard.SpagoBIDeployWizardFormPage.java

License:Mozilla Public License

/** Creates the wizard form
 * @see IDialogPage#createControl(Composite)
 *///from  ww w. j a va 2  s  . c o m
public void createControl(Composite parent) {
    logger.debug("IN");
    Shell shell = parent.getShell();
    //shell.setSize(1300,500);
    monitor = new ProgressMonitorPart(getShell(), null);

    Object objSel = selection.toList().get(0);
    File fileSelected = (File) objSel;
    projectName = fileSelected.getProject().getName();

    final SpagoBIServerObjectsFactory proxyObjects;
    // first of all get info from server      
    SDKProxyFactory proxyFactory = null;
    try {
        proxyObjects = new SpagoBIServerObjectsFactory(projectName);

        //         Server server = new ServerHandler().getCurrentActiveServer(projectName);
        //          proxyFactory=new SDKProxyFactory(server);
    } catch (NoActiveServerException e1) {
        logger.error("No active server found", e1);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "No active server found");
        return;
    }

    final NotAllowedOperationStudioException notAllowedOperationStudioException = new NotAllowedOperationStudioException();
    final RetrievingObjectsException retrievingObjectsException = new RetrievingObjectsException();

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Deploy a new Document: ", IProgressMonitor.UNKNOWN);

            String monitoring = "Engines";
            try {

                enginesList = proxyObjects.getServerEngines().getEnginesList();
                monitoring = "Datasets";
                datasetList = proxyObjects.getServerDatasets().getDataSetList();
                monitoring = "Datasources";
                datasourceList = proxyObjects.getServerDataSources().getDataSourceList();
                monitoring = "Functionalities ";
                functionality = proxyObjects.getServerDocuments().getDocumentsAsTree(null);

                if (enginesList == null || datasetList == null || datasourceList == null) {
                    String prog = enginesList == null ? "Engines"
                            : datasetList == null ? "Datasets" : datasourceList == null ? "Datasources" : "";
                    logger.error(prog + " list retrieved is empty: check server log for possible error");
                    retrievingObjectsException.setObject(prog);
                }

            } catch (Exception e) {
                if (e.getClass().toString()
                        .equalsIgnoreCase("class it.eng.spagobi.sdk.exceptions.NotAllowedOperationException")) {
                    logger.error("NotAllowed User Permission", e);
                    notAllowedOperationStudioException.setNotAllowed(true);
                } else {
                    logger.error("Error in retrieving " + monitoring
                            + ": check server connection; otherwise check server log", e);
                    MessageDialog.openError(getShell(), "Error in communication with server",
                            "Error in comunication with SpagoBi Server ; check its definition and check if the service is avalaible");
                }
                return;
            }
            monitor.done();
            if (monitor.isCanceled())
                logger.error("The long running operation was cancelled");
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e1) {
        logger.error(
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible",
                e1);
        dialog.close();
        MessageDialog.openError(getShell(), "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    } catch (InterruptedException e1) {
        logger.error("No comunication with SpagoBI server", e1);
        dialog.close();
        MessageDialog.openError(getShell(), "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    }
    dialog.close();

    if (retrievingObjectsException.getObject() != null) {
        MessageDialog.openWarning(getShell(), "Empty List", retrievingObjectsException.getObject()
                + " list is empty: probably due to an error in server; check server log.");
    }

    if (notAllowedOperationStudioException.isNotAllowed()) {
        logger.error("User has no permission to complete the operation");
        MessageDialog.openError(getShell(), "Error", "User has no permission to complete the operation");
        return;
    }

    FillLayout fl2 = new FillLayout();
    fl2.type = SWT.HORIZONTAL;
    parent.setLayout(fl2);

    Composite left = new Composite(parent, SWT.BORDER);
    Composite right = new Composite(parent, SWT.BORDER);

    GridLayout gl = new GridLayout();
    int ncol = 2;
    gl.numColumns = ncol;
    left.setLayout(gl);

    FillLayout fl = new FillLayout();
    right.setLayout(fl);

    // *************** Left Layout **********************

    new Label(left, SWT.NONE).setText("Label:");
    labelText = new Text(left, SWT.BORDER);
    labelText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    labelText.setTextLimit(SpagoBIStudioConstants.BIOBJECT_LABEL_LIMIT);
    labelText.addListener(SWT.KeyUp, new Listener() {
        public void handleEvent(Event event) {
            //check if page is complete
            boolean complete = isPageComplete();
            if (complete) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });

    new Label(left, SWT.NONE).setText("Name:");
    nameText = new Text(left, SWT.BORDER);
    nameText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    nameText.setTextLimit(SpagoBIStudioConstants.BIOBJECT_NAME_LIMIT);
    nameText.addListener(SWT.KeyUp, new Listener() {
        public void handleEvent(Event event) {
            //check if page is complete
            boolean complete = isPageComplete();
            if (complete) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });

    new Label(left, SWT.NONE).setText("Description:");
    descriptionText = new Text(left, SWT.BORDER);
    descriptionText.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    descriptionText.setTextLimit(SpagoBIStudioConstants.BIOBJECT_DESCRIPTION_LIMIT);

    typeLabel = BiObjectUtilities.getTypeFromExtension(fileSelected.getName());

    int indexPoint = fileSelected.getName().indexOf('.');
    String extension = "";
    if (indexPoint != -1) {
        extension = fileSelected.getName().substring(indexPoint + 1);
    }

    if (typeLabel == null) {
        logger.error("File " + fileSelected.getName() + " has unknown exstension");
        MessageDialog.openError(getShell(), "No type",
                "File " + fileSelected.getName() + " has unknown exstension");
        return;
    }

    new Label(left, SWT.NONE).setText("Type: ");
    new Label(left, SWT.NONE).setText(typeLabel);

    new Label(left, SWT.NONE).setText("Engines");
    engineCombo = new Combo(left, SWT.NONE | SWT.READ_ONLY);
    engineCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    engineLabelIdMap = new HashMap<String, Integer>();

    if (enginesList != null && enginesList.length != 0) {
        for (Engine engine : enginesList) {
            if (engine.getDocumentType().equalsIgnoreCase(typeLabel)) {

                // if type == REPORT select directly the right engine
                //BIRT
                if (typeLabel.equalsIgnoreCase(SpagoBIStudioConstants.REPORT_TYPE)
                        && extension.equals(SpagoBIStudioConstants.BIRT_REPORT_ENGINE_EXTENSION)) {
                    if (engine.getDriverClassName().equals(SpagoBIStudioConstants.BIRT_ENGINE_DRIVER)) {
                        engineCombo.add(engine.getLabel());
                        engineLabelIdMap.put(engine.getLabel(), engine.getId());
                    }
                } else //JASPER
                if (typeLabel.equalsIgnoreCase(SpagoBIStudioConstants.REPORT_TYPE)
                        && extension.equals(SpagoBIStudioConstants.JASPER_REPORT_ENGINE_EXTENSION)) {
                    if (engine.getDriverClassName().equals(SpagoBIStudioConstants.JASPER_ENGINE_DRIVER)) {
                        engineCombo.add(engine.getLabel());
                        engineLabelIdMap.put(engine.getLabel(), engine.getId());
                    }
                } else // CHART 
                if (typeLabel.equalsIgnoreCase(SpagoBIStudioConstants.CHART_TYPE)
                        && extension.equals(SpagoBIStudioConstants.CHART_ENGINE_EXTENSION)) {
                    if (engine.getClassName().equals(SpagoBIStudioConstants.CHART_ENGINE_CLASS)) {
                        engineCombo.add(engine.getLabel());
                        engineLabelIdMap.put(engine.getLabel(), engine.getId());
                    }
                } else // DASHBOARD
                if (typeLabel.equalsIgnoreCase(SpagoBIStudioConstants.CHART_TYPE)
                        && extension.equals(SpagoBIStudioConstants.DASHBOARD_ENGINE_EXTENSION)) {
                    if (engine.getClassName().equals(SpagoBIStudioConstants.DASHBOARD_ENGINE_CLASS)) {
                        engineCombo.add(engine.getLabel());
                        engineLabelIdMap.put(engine.getLabel(), engine.getId());
                    }
                } else // GEO
                if (typeLabel.equalsIgnoreCase(SpagoBIStudioConstants.GEO_TYPE)
                        && extension.equals(SpagoBIStudioConstants.GEO_ENGINE_EXTENSION)) {
                    if (engine.getDriverName().equals(SpagoBIStudioConstants.GEO_ENGINE_DRIVER)) {
                        engineCombo.add(engine.getLabel());
                        engineLabelIdMap.put(engine.getLabel(), engine.getId());
                    }
                } else // CONSOLE
                if (typeLabel.equalsIgnoreCase(SpagoBIStudioConstants.CONSOLE_TYPE)
                        && extension.equals(SpagoBIStudioConstants.CONSOLE_TEMPLATE_EXTENSION)) {
                    if (engine.getDriverName().equals(SpagoBIStudioConstants.CONSOLE_ENGINE_DRIVER)) {
                        engineCombo.add(engine.getLabel());
                        engineLabelIdMap.put(engine.getLabel(), engine.getId());
                    }
                }

                else {
                    engineCombo.add(engine.getLabel());
                    engineLabelIdMap.put(engine.getLabel(), engine.getId());
                }
            }
        }
    }

    // Select dataset
    new Label(left, SWT.NONE).setText("Dataset");
    dataSetCombo = new Combo(left, SWT.NONE | SWT.READ_ONLY);
    String labelDatasetInside = null;
    try {
        labelDatasetInside = fileSelected.getPersistentProperty(SpagoBIStudioConstants.DATASET_LABEL_INSIDE);
    } catch (Exception e) {
        logger.warn("error in reading dataset sppecified inside template: go on anyway");
    }

    String[] datasetLabels = new String[datasetList.length];
    dataSetLabelIdMap = new HashMap<String, Integer>();
    for (int i = 0; i < datasetLabels.length; i++) {
        IDataSet dataSet = datasetList[i];
        datasetLabels[i] = dataSet.getLabel();
        dataSetLabelIdMap.put(dataSet.getLabel(), dataSet.getId());
    }

    if (labelDatasetInside == null || labelDatasetInside.equalsIgnoreCase("")) {

        // sort the items

        Arrays.sort(datasetLabels);
        dataSetCombo.setItems(datasetLabels);
        //      for (SDKDataSet dataSet : datasetList) {
        //         dataSetCombo.add(dataSet.getLabel());
        //         dataSetLabelIdMap.put(dataSet.getLabel(), dataSet.getId());
        //      }

        dataSetCombo.setEnabled(false);
    } else {
        insideLabelDataset = labelDatasetInside;
        String[] insideLabel = new String[] { labelDatasetInside };
        dataSetCombo.setItems(insideLabel);
        int indexOfLabel = dataSetCombo.indexOf(labelDatasetInside);
        dataSetCombo.select(indexOfLabel);
        dataSetCombo.setEnabled(false);
    }

    // Select datasource
    new Label(left, SWT.NONE).setText("Datasource");
    dataSourceCombo = new Combo(left, SWT.NONE | SWT.READ_ONLY);
    dataSourceLabelIdMap = new HashMap<String, Integer>();
    String[] datasourceLabels = new String[datasourceList.length];
    for (int i = 0; i < datasourceLabels.length; i++) {
        DataSource dataSource = datasourceList[i];
        datasourceLabels[i] = dataSource.getLabel();
        dataSourceLabelIdMap.put(dataSource.getLabel(), dataSource.getId());
    }
    Arrays.sort(datasourceLabels);
    dataSourceCombo.setItems(datasourceLabels);

    //      for (SDKDataSource dataSource : datasourceList) {
    //         dataSourceCombo.add(dataSource.getLabel());
    //         dataSourceLabelIdMap.put(dataSource.getLabel(), dataSource.getId());
    //      }

    dataSourceCombo.setEnabled(false);

    engineCombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent event) {
            String comboText = engineCombo.getText();
            boolean found = false;
            Integer id = engineLabelIdMap.get(comboText);
            Engine engine = null;
            for (int i = 0; i < enginesList.length; i++) {
                Engine temp = enginesList[i];
                if (temp.getId().equals(id)) {
                    engine = temp;
                    found = true;
                }
            }
            if (engine != null) {
                boolean useDataset = engine.getUseDataSet() != null ? engine.getUseDataSet() : false;
                boolean useDatasource = engine.getUseDataSource() != null ? engine.getUseDataSource() : false;
                dataSetCombo.setEnabled(useDataset);
                dataSourceCombo.setEnabled(useDatasource);

            }

        }
    });

    // if only one choice is allowed set it
    if (engineCombo.getItemCount() == 1) {
        engineCombo.select(0);
        //         engineCombo.setEnabled(false);

    }

    // Select State
    new Label(left, SWT.NONE).setText("State");
    stateCombo = new Combo(left, SWT.NONE | SWT.READ_ONLY);
    stateCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    stateCombo.add("REL");
    stateCombo.add("DEV");
    stateCombo.add("TEST");
    stateCombo.add("SUSP");

    new Label(left, SWT.NONE).setText("Refresh Seconds:");
    refreshSecondsSpinner = new Spinner(left, SWT.NONE);

    setControl(left);

    // *************** Right Composite **********************

    SdkSelectFolderTreeGenerator treeGenerator = new SdkSelectFolderTreeGenerator();
    tree = treeGenerator.generateTree(right, functionality);

    tree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            //check if page is complete
            boolean complete = isPageComplete();
            if (complete) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });

    setControl(right);

}

From source file:it.eng.spagobi.studio.core.wizards.downloadModelWizard.SpagoBIDownloadModelWizardPage.java

License:Mozilla Public License

/** Creates the wizard form
 * @see IDialogPage#createControl(Composite)
 *///  www .j av  a  2s .  c om
public void createControl(Composite parent) {
    logger.debug("IN");
    monitor = new ProgressMonitorPart(getShell(), null);
    initialize();

    Composite container = new Composite(parent, SWT.NULL);
    FillLayout layout = new FillLayout();
    container.setLayout(layout);

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Download models", IProgressMonitor.UNKNOWN);
            try {

                SpagoBIServerObjectsFactory spagoBIServerObjects = new SpagoBIServerObjectsFactory(projectName);
                models = spagoBIServerObjects.getServerDocuments().getAllDatamartModels();
            } catch (NoActiveServerException e1) {
                SpagoBILogger.errorLog("No active server found", e1);
                MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Error", "No active server found");
                return;
            } catch (Exception e) {
                SpagoBILogger.errorLog("No comunication with SpagoBI server", e);
                MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "No comunication with server",
                        "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
                return;
            }
            monitor.done();
            if (monitor.isCanceled())
                SpagoBILogger.errorLog("Operation not ended",
                        new InterruptedException("The long running operation was cancelled"));
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e1) {
        SpagoBILogger.errorLog("No comunication with SpagoBI server", e1);
        dialog.close();
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    } catch (InterruptedException e2) {
        SpagoBILogger.errorLog("No comunication with SpagoBI server", e2);
        dialog.close();
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    }
    dialog.close();

    try {
        if (models == null || models.size() == 0) {
            SpagoBILogger.warningLog("No new models to download found");
            MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "Warning", "No Models to download found on the server!");
            return;
        }
        tree = generateTree(container, models);
        SpagoBILogger.infoLog("getChildren: " + tree.getItems().length);
        if (tree == null || !isViewTree()) {
            SpagoBILogger.warningLog("No new models to download found");
            MessageDialog.openWarning(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "Warning", "No new Models to download found!");
            return;
        }

    } catch (Exception e) {
        SpagoBILogger.errorLog("Error while generating tree", e);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "Error in generating the tree, control if SpagoBI Server is defined and service is avalaible");
    }

    tree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            //check if page is complete
            boolean complete = isPageComplete(event);
            if (complete) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });

    setControl(container);
    logger.debug("OUT");

}

From source file:it.eng.spagobi.studio.core.wizards.downloadWizard.SpagoBIDownloadWizardPage.java

License:Mozilla Public License

/** Creates the wizard form
 * @see IDialogPage#createControl(Composite)
 *///from  w  w w.  ja  v  a  2 s. c o m
public void createControl(Composite parent) {
    logger.debug("IN");
    monitor = new ProgressMonitorPart(getShell(), null);
    initialize();

    Composite container = new Composite(parent, SWT.NULL);
    FillLayout layout = new FillLayout();
    container.setLayout(layout);
    //      SDKProxyFactory proxyFactory = null;
    //      try{
    //         Server server = new ServerHandler().getCurrentActiveServer(projectName);
    //         proxyFactory=new SDKProxyFactory(server);
    //      }
    //      catch (NoActiveServerException e1) {
    //         SpagoBILogger.errorLog("No active server found", e1);         
    //         MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
    //               "Error", "No active server found");   
    //         return;
    //      }

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Download documents tree", IProgressMonitor.UNKNOWN);
            SDKProxyFactory proxyFactory = null;
            //            try {
            //               Server server = new ServerHandler().getCurrentActiveServer(projectName);
            //               proxyFactory=new SDKProxyFactory(server);
            //            }
            //            catch (NoActiveServerException e1) {
            //               SpagoBILogger.errorLog("No active server found", e1);         
            //               MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 
            //                     "Error", "No active server found");   
            //               return;
            //            }

            try {

                SpagoBIServerObjectsFactory spagoBIServerObjects = new SpagoBIServerObjectsFactory(projectName);

                functionality = spagoBIServerObjects.getServerDocuments().getDocumentsAsTree(null);

            } catch (NoActiveServerException e1) {
                SpagoBILogger.errorLog("No active server found", e1);
                MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "Error", "No active server found");
                return;
            } catch (Exception e) {
                SpagoBILogger.errorLog("No comunication with SpagoBI server", e);
                MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                        "No comunication with server",
                        "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
                return;
            }
            monitor.done();
            if (monitor.isCanceled())
                SpagoBILogger.errorLog("Operation not ended",
                        new InterruptedException("The long running operation was cancelled"));
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e1) {
        SpagoBILogger.errorLog("No comunication with SpagoBI server", e1);
        dialog.close();
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    } catch (InterruptedException e1) {
        SpagoBILogger.errorLog("No comunication with SpagoBI server", e1);
        dialog.close();
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "No comunication with server",
                "Error in comunication with SpagoBi Server; check its definition and check if the service is avalaible");
        return;
    }
    dialog.close();

    SdkFunctionalityTreeGenerator treeGenerator = new SdkFunctionalityTreeGenerator();

    try {
        tree = treeGenerator.generateTree(container, functionality);
    } catch (Exception e) {
        SpagoBILogger.errorLog("Error while generating tree", e);
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "Error in generating the tree, control if SpagoBI Server is defined and service is avalaible");
    }

    tree.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            //check if page is complete
            boolean complete = isPageComplete();
            if (complete) {
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
        }
    });

    setControl(container);
    logger.debug("OUT");

}

From source file:it.eng.spagobi.studio.documentcomposition.util.DocumentsContainedHandler.java

License:Mozilla Public License

/** called to refresh metatas of contained documetns
 * /*from   w  ww.  j a v a  2  s .  c  om*/
 * @param container
 */
public void refreshMetadataOfContainedDocuments(final Composite container) {
    logger.debug("IN");
    final MetadataHandler metadataHandler = new MetadataHandler();
    final NoDocumentException noDocumentException = new NoDocumentException();
    final NoActiveServerException noActiveServerException = new NoActiveServerException();

    /**
     *  Refresh of metadata of all documents contained in composite document
     */

    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            monitor.beginTask("Refreshing ", IProgressMonitor.UNKNOWN);
            try {
                logger.debug("Monitor for metadata refresh of contained documents has started");
                DocumentComposition doccomp = Activator.getDefault().getDocumentComposition();
                Vector<Document> documents = doccomp.getDocumentsConfiguration().getDocuments();
                if (documents == null) {
                    logger.debug("No documents present, refresh finished");
                    return;
                }
                String label = null;

                // run all contained documents
                for (Iterator iterator = documents.iterator(); iterator.hasNext();) {
                    Document document = (Document) iterator.next();
                    logger.debug("document eith label " + document.getSbiObjLabel());

                    noDocumentException.setDocumentLabel(null);

                    String localFileName = document.getLocalFileName();

                    IEditorPart editorPart = DocCompUtilities
                            .getEditorReference(DocCompUtilities.DOCUMENT_COMPOSITION_EDITOR_ID);
                    String projectName = ((DocumentCompositionEditor) editorPart).getDesigner()
                            .getProjectName();

                    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                    IPath workspacePath = root.getLocation();
                    IProject project = root.getProject(projectName);
                    IPath projectLocation = project.getLocation();

                    // get file from workspace
                    IPath pathRetrieved = FileFinder.retrieveFile(localFileName, projectLocation.toString(),
                            workspacePath);
                    if (pathRetrieved != null) {
                        logger.debug("search for file on " + pathRetrieved.toOSString());
                        IFile fileToGet = ResourcesPlugin.getWorkspace().getRoot().getFile(pathRetrieved);
                        if (fileToGet.exists()) {
                            logger.debug("file found " + fileToGet.getName());
                            label = fileToGet.getPersistentProperty(SpagoBIStudioConstants.DOCUMENT_LABEL);
                            noDocumentException.setDocumentLabel(label);

                            metadataHandler.refreshMetadata(fileToGet, noDocumentException,
                                    noActiveServerException);
                            // after refreshing there is to update the object
                            logger.debug("update current object MetadataDocument");
                            final MetadataDocument metadataDocument = refreshObject(document, fileToGet);
                            // refresh also graphical view
                            logger.debug("refresh graphic");
                            if (metadataDocument != null) {
                                logger.debug("metadata object refreshed");

                                new Thread(new Runnable() {
                                    public void run() {
                                        try {
                                            Thread.sleep(1000);
                                        } catch (Exception e) {
                                        }
                                        Display.getDefault().asyncExec(new Runnable() {
                                            public void run() {
                                                try {
                                                    refreshGraphic(metadataDocument);
                                                } catch (CoreException e) {
                                                    MessageDialog.openWarning(container.getShell(), "Warning",
                                                            "COuld not refresh graphic properties: select any document to refresh it manually");
                                                }

                                            }
                                        });
                                    }
                                }).start();

                            } else {
                                logger.error("metadata object could not be refreshed refreshed");
                                throw noDocumentException;
                            }

                        }
                    }
                }

            } catch (Exception e) {
                logger.error("Error in monitor retieving metadata ", e);
                MessageDialog.openError(container.getShell(), "Exception", "Exception");
            }
        }
    };

    ProgressMonitorDialog dialog = new ProgressMonitorDialog(container.getShell());
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e1) {
        logger.error("No comunication with SpagoBI server: could not refresh metadata", e1);
        dialog.close();
        MessageDialog.openError(container.getShell(), "Error",
                "No comunication with server: Could not refresh metadata");
        return;
    } catch (InterruptedException e1) {
        logger.error("No comunication with SpagoBI server: could not refresh metadata", e1);
        dialog.close();
        MessageDialog.openError(container.getShell(), "Error",
                "No comunication with server: Could not refresh metadata");
        return;
    }

    dialog.close();

    if (noActiveServerException.isNoServer()) {
        logger.error("No Server is defined active");
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Error refresh", "No Server is defined active");
        return;
    }
    if (noDocumentException.isNoDocument()) {
        logger.error("Document " + noDocumentException.getDocumentLabel() != null
                ? noDocumentException.getDocumentLabel()
                : " " + " not retrieved; check it is still on server and you have enough permission to reach it");
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "Document "
                        + (noDocumentException.getDocumentLabel() != null
                                ? noDocumentException.getDocumentLabel()
                                : " ")
                        + " not retrieved; check it is still on server and you have enough permission to reach it");
        return;
    }

    MessageDialog.openInformation(container.getShell(), "Information", "Metadata refreshed");
    logger.debug("OUT");
}

From source file:it.scoppelletti.sdk.ide.IDEPlugin.java

License:Apache License

/**
 * Esegue un&rsquo;operazione con notifica dell&rsquo;avanzamento.
 * /* w  ww. j  a va2s.c  om*/
 * @param op Operazione.
 * @since    1.1.0
 */
public void runOperation(IRunnableWithProgress op) throws InvocationTargetException {
    ProgressMonitorDialog dlg;

    if (op == null) {
        throw new NullPointerException("op");
    }

    dlg = new ProgressMonitorDialog(getCurrentDisplay().getActiveShell());
    try {
        dlg.run(false, false, op);
    } catch (InterruptedException ex) {
        StatusUtils.logStatus(ex);
    }
}

From source file:jp.co.dgic.eclipse.jdt.internal.coverage.ui.CoverageReportView.java

License:Open Source License

private void exportHtmlReport() {
    try {/*from   w  ww .j  a  v a 2 s  . c  o m*/
        String outputDirectory = getReportOutputDirectory();

        if (outputDirectory == null)
            return;

        reportOutputDirectory = outputDirectory;

        String reportCharset = DJUnitProjectPropertyPage.readCoverageReportCharset(currentProject);
        System.setProperty("djunit.html.charset", reportCharset);
        System.setProperty("djunit.src.file.encoding", currentProject.getDefaultCharset());

        String[] args = new String[6];
        args[0] = "-i";
        args[1] = getCoverageWorkingDirectory() + "/jcoverage.ser";
        args[2] = "-s";
        args[3] = getSourceDirectories();
        args[4] = "-o";
        args[5] = outputDirectory;

        HtmlReportExportProcess exportProcess = new HtmlReportExportProcess(args);
        Shell shell = new Shell(Display.getDefault());
        ProgressMonitorDialog monitorDialog = new ProgressMonitorDialog(shell);

        monitorDialog.run(true, true, exportProcess);

    } catch (Throwable t) {
        DJUnitPlugin.log(t);
        String message = t.getMessage();
        if (t.getMessage() == null) {
            message = t.toString();
        }
        MessageBox md = new MessageBox(new Shell(Display.getDefault()), SWT.OK | SWT.ICON_ERROR);
        md.setText("Error");
        md.setMessage(message);
        md.open();
    }
}