Example usage for org.eclipse.jface.viewers IStructuredSelection toList

List of usage examples for org.eclipse.jface.viewers IStructuredSelection toList

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IStructuredSelection toList.

Prototype

public List toList();

Source Link

Document

Returns the elements in this selection as a List.

Usage

From source file:it.eng.spagobi.studio.chart.actions.NewChartAction.java

License:Mozilla Public License

public void run(IAction action) {
    SpagoBINewChartWizard sbindw = new SpagoBINewChartWizard();
    //      CommonViewer commViewer=((CommonNavigator) view).getCommonViewer();
    //      IStructuredSelection sel=(IStructuredSelection)commViewer.getSelection();
    IStructuredSelection sel = (IStructuredSelection) selection;

    Object objSel = sel.toList().get(0);
    Folder folderSel = null;//from   w  ww  .  jav  a2 s  . co  m
    try {
        // FolderSel is the folder in wich to insert the new template
        folderSel = (Folder) objSel;

        sbindw.init(PlatformUI.getWorkbench(), sel);
        // Create the wizard dialog
        WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                sbindw);
        // Open the wizard dialog
        dialog.open();

    } catch (Exception e) {
        logger.error("no selected folder", e);
        MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                "You must select a folder in wich to insert the chart");
    }

}

From source file:it.eng.spagobi.studio.core.actions.NewServerAction.java

License:Mozilla Public License

public void run(IAction action) {
    logger.debug("IN");
    NewServerWizard sbindw = new NewServerWizard();
    IStructuredSelection sel = (IStructuredSelection) selection;

    // go on only if you selected a folder
    Object objSel = sel.toList().get(0);
    Folder folderSel = null;//from w  w w.ja v a 2 s .  c o m
    folderSel = (Folder) objSel;

    // init wizard
    sbindw.init(PlatformUI.getWorkbench(), sel);
    // Create the wizard dialog
    WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            sbindw);
    // Open the wizard dialog
    dialog.open();
    logger.debug("OUT");

}

From source file:it.eng.spagobi.studio.core.services.datamartTemplate.UploadDatamartTemplateService.java

License:Mozilla Public License

public boolean datamartUpload() {
    logger.debug("IN");

    IStructuredSelection sel = (IStructuredSelection) selection;

    // go on only if is selected a document
    Object objSel = sel.toList().get(0);
    File fileSel = (File) objSel;
    projectname = fileSel.getProject().getName();
    modelFileName = fileSel.getName();/*w  w  w .  j  av  a 2s  .c  om*/

    logger.debug("get datamart.jar of model file name " + fileSel.getName());

    // refresh metadata_model folder
    refreshModelFolder(fileSel);

    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 false;
    }

    // First, check if there are any physical model objects marked as deleted
    PhysicalModelInitializer physicalModelInitializer = new PhysicalModelInitializer();
    List<ModelObject> markedElements = physicalModelInitializer
            .getElementsMarkedAsDeleted(businessModel.getPhysicalModel());
    if (!markedElements.isEmpty()) {
        DeleteElementsWarningForUploadDialog warningDialog = new DeleteElementsWarningForUploadDialog(
                markedElements);
        warningDialog.create();
        warningDialog.setBlockOnOpen(true);
        warningDialog.open();

    }

    if (markedElements.isEmpty()) {
        // check the constraints for hibernate mappings
        BusinessModelInitializer businessModelInitializer = new BusinessModelInitializer();
        List<Pair<BusinessRelationship, Integer>> incorrectRelationships = businessModelInitializer
                .checkRelationshipsConstraints(businessModel);
        int relationshipsWarningReturnCode = Window.CANCEL;
        if (!incorrectRelationships.isEmpty()) {
            BusinessModelRelationshipsCheckWarningDialog warningDialog = new BusinessModelRelationshipsCheckWarningDialog(
                    incorrectRelationships);
            warningDialog.create();
            warningDialog.setBlockOnOpen(true);
            relationshipsWarningReturnCode = warningDialog.open();
        }

        if (incorrectRelationships.isEmpty() || relationshipsWarningReturnCode == Window.OK) {
            return generateJarAndUpload(businessModel, fileSel);
        }

    }
    return false;

}

From source file:it.eng.spagobi.studio.core.services.dataset.DeployDatasetService.java

License:Mozilla Public License

/** if document has meadata associated do the automated deploy
 * //ww  w.  ja v a  2  s.  c  o m
 * @return if automated eply has been done
 */
public boolean tryAutomaticDeploy() {
    logger.debug("IN");

    IStructuredSelection sel = (IStructuredSelection) selection;

    // go on only if ysou 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 datasetId = null;
    String datasetLabel = null;
    String datasetCategory = null;
    try {
        datasetId = fileSel.getPersistentProperty(SpagoBIStudioConstants.DATASET_ID);
        datasetLabel = fileSel.getPersistentProperty(SpagoBIStudioConstants.DATASET_LABEL);
        datasetCategory = fileSel.getPersistentProperty(SpagoBIStudioConstants.DATASET_CATEGORY);
    } catch (CoreException e) {
        logger.error("Error in retrieving dataset Label", e);
    }

    // IF File selected has already an id of datasetassociated do the upload wiyhout asking further informations
    boolean automatic = false;
    boolean newDeployFromOld = false;
    if (datasetId != null) {
        logger.debug("Query already associated to dataset" + datasetId + " - " + datasetLabel
                + " - of category " + datasetCategory);
        final Integer idInteger = Integer.valueOf(datasetId);
        final String label2 = datasetLabel;
        final org.eclipse.core.internal.resources.File fileSel2 = fileSel;
        final NoDocumentException datasetException = new NoDocumentException();
        final NoActiveServerException noActiveServerException = new NoActiveServerException();
        final NotAllowedOperationStudioException notAllowedOperationStudioException = new NotAllowedOperationStudioException();
        IRunnableWithProgress op = new IRunnableWithProgress() {
            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(
                        "Deploying to dataset existing dataset with label: " + label2 + " and ID: " + idInteger,
                        IProgressMonitor.UNKNOWN);

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

                try {
                    logger.debug("dataset associated, upload the query to dataset " + label2);

                    SpagoBIServerObjectsFactory spagoBIServerObjects = new SpagoBIServerObjectsFactory(
                            projectname);

                    // check dataset still exists
                    IDataSet ds = spagoBIServerObjects.getServerDatasets().getDataSet(idInteger);
                    if (ds == null) {
                        datasetException.setNoDocument(true);
                        logger.warn("Dataset no more present on server: with id " + idInteger);
                    } else {
                        logger.debug("update query to dataset");

                        String queryStr = null;
                        String adaptedQueryStrList = null;
                        try {
                            JSONObject obj = JSONReader.createJSONObject(fileSel2);
                            queryStr = obj.optString("query");
                            logger.debug("query is " + queryStr);
                            adaptedQueryStrList = DeployDatasetService.adaptQueryToList(queryStr);
                            logger.debug("adapted query list is " + adaptedQueryStrList);

                            //solvedeccoqui
                            // only the query may be modified by meta so it is the only refreshed
                            ds.addToConfiguration(Dataset.QBE_JSON_QUERY, adaptedQueryStrList);
                            //ds.setJsonQuery(adaptedQueryStrList);
                            datasetException.setNoDocument(false);
                            Integer dsId = spagoBIServerObjects.getServerDatasets().saveDataSet(ds);
                            if (ds == null) {
                                logger.error("Error while uploading dataset on server; check log on server");
                                MessageDialog.openError(
                                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                                        "Error on deploy",
                                        "Error while uploading dataset; check server log to have details");

                            }

                            BiObjectUtilities.setFileDataSetMetaData(fileSel2, ds);

                        } catch (Exception e) {
                            logger.error("error in reading JSON object, update failed", e);
                        }

                    }
                }

                catch (NoActiveServerException e1) {
                    // no active server found 
                    noActiveServerException.setNoServer(true);
                } catch (RemoteException e) {
                    if (e.getClass().toString().equalsIgnoreCase(
                            "class it.eng.spagobi.sdk.exceptions.NotAllowedOperationException")) {
                        logger.error("Current User has no permission to deploy dataset", e);
                        notAllowedOperationStudioException.setNotAllowed(true);
                    } else {
                        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");
                    }
                }

                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 (datasetException.isNoDocument()) {
            logger.error("Document no more present");
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "Error upload",
                    "Dataset with ID " + idInteger + "  no more present on server; you can do a new deploy");
            sbdw.setNewDeployFromOld(true);
            newDeployFromOld = 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 (notAllowedOperationStudioException.isNotAllowed()) {
            logger.error("Current User has no permission to deploy dataset");
            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "",
                    "Current user has no permission to deploy dataset");
            return false;
        }

        if (!newDeployFromOld) {
            MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                    "Deploy succesfull", "Deployed to the associated dataset with label: " + datasetLabel
                            + " and ID: " + idInteger + " succesfull");
            logger.debug(
                    "Deployed to the associated document " + datasetLabel + " succesfull: ID: is " + idInteger);
            automatic = true;
        }
    } else {
        automatic = false;
    }

    if (!automatic || newDeployFromOld) {
        logger.debug("deploy a new Dataset: start wizard");
        // init wizard
        sbdw.init(PlatformUI.getWorkbench(), sel);
        // Create the wizard dialog
        WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                sbdw);
        dialog.setPageSize(650, 300);
        // Open the wizard dialog
        dialog.open();
    }

    logger.debug("OUT");
    return automatic;

}

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  a  v  a  2 s .co 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.modelTemplate.RestoreModelService.java

License:Mozilla Public License

public void RestoreModelTemplate() {

    IStructuredSelection sel = (IStructuredSelection) selection;

    // go on only if you selected a document (a file)
    Object objSel = sel.toList().get(0);
    File fileSel = null;// w  w w.j  ava 2 s .  co m
    try {
        fileSel = (File) objSel;
        projectName = fileSel.getProject().getName();
        modelName = fileSel.getName().substring(0,
                fileSel.getName().indexOf(SpagoBIStudioConstants.BACKUP_EXTENSION) - 1);
    } 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;
    }

    boolean restore = MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "Restore model template", "Confirm restore template for model " + modelName + " ?");
    if (restore) {
        logger.debug("Do the model template restore model with name  " + modelName);

        try {
            // get the directory
            Folder folder = (Folder) fileSel.getParent().getParent();
            String projectName = folder.getProject().getName();
            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IProject project = root.getProject(projectName);
            IPath pathFolder = folder.getProjectRelativePath();

            IPath pathNewFile = pathFolder.append(modelName);
            IFile newFile = project.getFile(pathNewFile);
            if (newFile.exists()) {
                newFile.delete(true, null);
            }
            newFile.create(fileSel.getContents(), true, null);
            fileSel.delete(true, null);

        } catch (Exception e1) {

            MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error",
                    "Error in restore the file");
            logger.error("Error in restore the file", e1);

            return;
        }

        String succesfullMessage = "Succesfully restore for the template " + modelName;

        logger.debug(succesfullMessage);
        MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                "Restore succesfull", succesfullMessage);

    }
}

From source file:it.eng.spagobi.studio.core.services.resources.ResourcesHandler.java

License:Mozilla Public License

public boolean deleteResources(ISelection selection) {

    logger.debug("IN");

    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    List<Object> selectedObjects = structuredSelection.toList();

    boolean delete = MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            "Delete Resource", "Confirm deleting resource(s)");
    if (delete) {
        for (Object selectedObject : selectedObjects) {
            if (selectedObject instanceof IResource) {
                IResource res = (IResource) selectedObject;
                deleteResource(res);/*from   w w w .ja  va  2s  .  co m*/
            }
        }
    }

    logger.debug("OUT");

    return true;
}

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 w ww  .ja v a 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 {//from ww  w . j  a v a2 s  .  co 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.views.actionProvider.ResourceNavigatorActionProvider.java

License:Mozilla Public License

public void fillContextMenu(IMenuManager menu) {
    logger.debug("IN");
    super.fillContextMenu(menu);

    IStructuredSelection sel = (IStructuredSelection) currentContext.getSelection();

    Object objSel = null;/*from  w  w  w .  ja  va  2 s .c o  m*/

    //setSpagoBIProjectWizard(menu);

    // actions to be done on one single selection
    if (sel.toList() != null && sel.toList().size() <= 1) {
        objSel = sel.toList().get(0);

        String currentState = ResourceNavigatorHandler.getStateOfSelectedObject(objSel);

        currentState = currentState != null ? currentState : "";

        // if it is a folder of analysis hierarchy
        if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FOLDER_ANALYSIS_HIER)) {
            logger.debug("Folder Analysis");
            // only if studio version
            if (Utilities.readBooleanProperty(properties,
                    SpagoBIStudioConstants.CONFIG_PROPERTY_ANALYSIS_DOCUMENT)) {
                setDownloadWizard(menu);
                setNewDocumentWizard(menu);
            }
        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FILE_ANALYSIS_HIER)) { // if it is a file of analysis hierarchy
            logger.debug("File ANalysis");
            if (Utilities.readBooleanProperty(properties,
                    SpagoBIStudioConstants.CONFIG_PROPERTY_ANALYSIS_DOCUMENT)) {
                setDeployWizard(menu);
                setRefreshWizard(menu);
            }
        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FOLDER_SERVER_HIER)) { // if it is a file of analysis hierarchy
            logger.debug("Folder Server");

            setServerWizard(menu);
        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FOLDER_MODEL_HIER)) { // if it is a file of analysis hierarchy
            logger.debug("Folder Model");

            setModelWizard(menu);
            setDownloadModelWizard(menu);
        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FILE_MODEL_HIER)) { // if it is a file of analysis hierarchy
            logger.debug("File under model hierarchy");
            setQueryWizard(menu);
            //            setJpaNavigator(menu);
            setUploadDatamartTemplateWizard(menu);
            setRefreshModelWizard(menu);
        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FILE_OLAP_HIER)) { // if it is a file of analysis hierarchy
            logger.debug("File under olap hierarchy");
            setDeployOlapTemplateWizard(menu);

        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FILE_BCK_MODEL_HIER)) { // if it is a file of backup model
            logger.debug("File under backup model hierarchy");
            setRestoreModel(menu);
        } else if (currentState.equalsIgnoreCase(ResourceNavigatorHandler.FILE_METAQUERY_HIER)) { // if it is a file of analysis hierarchy
            logger.debug("File under model hierarchy");
            setDeployDatasetWizard(menu);
        }
    }

    List<IStructuredSelection> selList = sel.toList();

    if (!ResourceNavigatorHandler.isSelectedObjSystemFolder(selList)) // model has it's own delete      
    { // if area files of analysis hierarchy
        logger.debug("Folder not system");
        setDeleteResourceWizard(menu);
    }

    IContributionItem[] contributionItems = menu.getItems();
    for (int j = 0; j < contributionItems.length; j++) {
        IContributionItem conItem = contributionItems[j];
        //System.out.println(conItem.toString());
        //      menu.remove(conItem);
    }

}