Search in sources :

Example 1 with IKaleoConnection

use of com.liferay.ide.kaleo.core.IKaleoConnection in project liferay-ide by liferay.

the class WorkflowDropAdapterAssistant method handleDrop.

@Override
public IStatus handleDrop(CommonDropAdapter aDropAdapter, DropTargetEvent aDropTargetEvent, Object aTarget) {
    if (aTarget instanceof WorkflowDefinitionsFolder) {
        WorkflowDefinitionsFolder folder = (WorkflowDefinitionsFolder) aTarget;
        IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(folder.getParent());
        TransferData transferData = aDropTargetEvent.currentDataType;
        if (LocalSelectionTransfer.getTransfer().isSupportedType(transferData)) {
            Object dropData = LocalSelectionTransfer.getTransfer().getSelection();
            if (dropData instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) dropData;
                Object element = selection.getFirstElement();
                if (element instanceof IFile) {
                    IFile file = (IFile) element;
                    Runnable runnable = new Runnable() {

                        public void run() {
                            folder.clearCache();
                            Runnable runnable = new Runnable() {

                                public void run() {
                                    IViewPart serversView = UIUtil.showView("org.eclipse.wst.server.ui.ServersView");
                                    CommonViewer viewer = (CommonViewer) serversView.getAdapter(CommonViewer.class);
                                    viewer.refresh(true);
                                }
                            };
                            Display.getDefault().asyncExec(runnable);
                        }
                    };
                    new UploadWorkflowFileJob(kaleoConnection, file, runnable).schedule();
                }
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) IFile(org.eclipse.core.resources.IFile) TransferData(org.eclipse.swt.dnd.TransferData) CommonViewer(org.eclipse.ui.navigator.CommonViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UploadWorkflowFileJob(com.liferay.ide.kaleo.ui.util.UploadWorkflowFileJob)

Example 2 with IKaleoConnection

use of com.liferay.ide.kaleo.core.IKaleoConnection in project liferay-ide by liferay.

the class WorkflowDefinitionsCustomContentProvider method getPipelinedChildren.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void getPipelinedChildren(Object parent, Set currentChildren) {
    if (parent instanceof IServer) {
        IServer server = (IServer) parent;
        /*
			 * IServerListener listener = new IServerListener() {

			 *
			 *
			 * @Override public void serverChanged( ServerEvent event ) { try {
			 * WorkflowDefinitionsCustomContentProvider.checkApiStatuses.
			 * remove( server.getId() ); refreshUI( (NavigatorContentService)
			 * getConfig().getService(), server ); } catch( Exception e) {} } };
			 * server.addServerListener( listener );
			 */
        if (server.getServerState() == IServer.STATE_STARTED) {
            WorkflowDefinitionsFolder definitionsNode = _workflowDefinitionFolders.get(server.getId());
            if (definitionsNode == null) {
                IStatus checkApiStatus = _checkApiStatuses.get(server.getId());
                if (checkApiStatus == null) {
                    Job checkJob = new Job("Checking for Kaleo Designer API...") {

                        @Override
                        protected IStatus run(IProgressMonitor monitor) {
                            try {
                                IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(server);
                                KaleoCore.updateKaleoConnectionSettings(KaleoUtil.getLiferayServer(server, monitor), kaleoConnection);
                                kaleoConnection.getKaleoDefinitions();
                                kaleoConnection.getKaleoDraftWorkflowDefinitions();
                                WorkflowDefinitionsCustomContentProvider.this._checkApiStatuses.put(server.getId(), Status.OK_STATUS);
                                refreshUI((NavigatorContentService) getConfig().getService(), server);
                            } catch (Exception e) {
                                WorkflowDefinitionsCustomContentProvider.this._checkApiStatuses.put(server.getId(), KaleoUI.createErrorStatus(e));
                            }
                            return Status.OK_STATUS;
                        }
                    };
                    checkJob.schedule();
                } else {
                    if (checkApiStatus.isOK()) {
                        _insertDefinitionsNode(server, currentChildren);
                        WorkflowDefinitionsCustomContentProvider.this._checkApiStatuses.put(server.getId(), null);
                    } else {
                        KaleoUI.logInfo("Kaleo Workflow API unavailable.", checkApiStatus);
                    }
                }
            } else {
                if (!currentChildren.contains(definitionsNode)) {
                    currentChildren.add(definitionsNode);
                    // make sure children are cached.
                    definitionsNode.getChildren();
                }
            }
        } else {
            _workflowDefinitionFolders.put(server.getId(), null);
            _checkApiStatuses.put(server.getId(), null);
        }
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 3 with IKaleoConnection

use of com.liferay.ide.kaleo.core.IKaleoConnection in project liferay-ide by liferay.

the class PublishWorkflowDefinitionAction method perform.

@Override
public void perform(Object node) {
    if (getSelectionProvider() instanceof CommonViewer && node instanceof WorkflowDefinitionEntry) {
        WorkflowDefinitionEntry definitionNode = (WorkflowDefinitionEntry) node;
        Job publishJob = new Job("Publishing workflow draft definition") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(definitionNode.getParent().getParent());
                try {
                    kaleoConnection.publishKaleoDraftDefinition(definitionNode.getName(), definitionNode.getTitleMap(), definitionNode.getContent(), definitionNode.getCompanyId() + "", definitionNode.getUserId() + "", definitionNode.getGroupId() + "");
                } catch (KaleoAPIException kapie) {
                    kapie.printStackTrace();
                }
                WorkflowDefinitionsFolder definitionsFolder = (WorkflowDefinitionsFolder) definitionNode.getParent();
                CommonViewer viewer = (CommonViewer) getSelectionProvider();
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        definitionsFolder.clearCache();
                        viewer.refresh(true);
                    }
                });
                return Status.OK_STATUS;
            }
        };
        publishJob.schedule();
    }
}
Also used : WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) CommonViewer(org.eclipse.ui.navigator.CommonViewer) KaleoAPIException(com.liferay.ide.kaleo.core.KaleoAPIException) Job(org.eclipse.core.runtime.jobs.Job) WorkflowDefinitionsFolder(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsFolder)

Example 4 with IKaleoConnection

use of com.liferay.ide.kaleo.core.IKaleoConnection in project liferay-ide by liferay.

the class WorkflowDefinitionEditor method _saveWorkflowDefinitionEntry.

private void _saveWorkflowDefinitionEntry(WorkflowDefinitionEditorInput definitionInput) {
    StructuredTextEditor sourceEditor = getXmlEditor();
    WorkflowDefinitionEntry definition = definitionInput.getWorkflowDefinitionEntry();
    String titleMap = definition.getTitleMap();
    String titleCurrentValue = definition.getTitleCurrentValue();
    IDocumentProvider documentProvider = sourceEditor.getDocumentProvider();
    IDocument document = documentProvider.getDocument(getEditorInput());
    String definitionContent = document.get();
    String[] newTitleMap = new String[1];
    if ((titleCurrentValue != null) && (titleMap != null)) {
        try {
            String localeCode = Locale.getDefault().toString();
            JSONObject jsonTitleMap = new JSONObject(titleMap);
            Iterator<?> keys = jsonTitleMap.keys();
            while ((keys != null) && keys.hasNext()) {
                Object key = keys.next();
                String value = jsonTitleMap.getString(key.toString());
                if ((value != null) && value.contains(titleCurrentValue)) {
                    localeCode = key.toString();
                    break;
                }
            }
            jsonTitleMap.put(localeCode, titleCurrentValue);
            newTitleMap[0] = jsonTitleMap.toString();
        } catch (Exception e) {
        }
    } else {
        newTitleMap[0] = definition.getTitleMap();
    }
    if (empty(newTitleMap[0])) {
        try {
            newTitleMap[0] = KaleoUtil.createJSONTitleMap(definition.getTitle());
        } catch (JSONException jsone) {
        }
    }
    int draftVersion = definition.getDraftVersion() + 1;
    if (draftVersion == 0) {
        draftVersion = 1;
    }
    int newDraftVersion = draftVersion;
    Job saveWorkflowEntry = new Job("Saving kaleo workflow entry.") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IStatus retval = Status.OK_STATUS;
            try {
                JSONObject updatedDraftDefinition = null;
                IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(definition.getParent().getParent());
                try {
                    JSONObject latestDraftDefinition = kaleoConnection.getLatestKaleoDraftDefinition(definition.getName(), definition.getVersion(), definition.getCompanyId());
                    if (latestDraftDefinition != null) {
                        updatedDraftDefinition = kaleoConnection.updateKaleoDraftDefinition(definition.getName(), newTitleMap[0], definitionContent, latestDraftDefinition.getInt("version"), latestDraftDefinition.getInt("draftVersion"), definition.getCompanyId(), definition.getUserId());
                    } else {
                        updatedDraftDefinition = kaleoConnection.addKaleoDraftDefinition(definition.getName(), newTitleMap[0], definitionContent, definition.getVersion(), newDraftVersion, definition.getUserId(), definition.getGroupId());
                    }
                } catch (Exception e) {
                    updatedDraftDefinition = kaleoConnection.addKaleoDraftDefinition(definition.getName(), newTitleMap[0], definitionContent, definition.getVersion(), newDraftVersion, definition.getUserId(), definition.getGroupId());
                }
                WorkflowDefinitionEntry newNode = WorkflowDefinitionEntry.createFromJsObject(updatedDraftDefinition);
                newNode.setParent(definition.getParent());
                newNode.setCompanyId(definition.getCompanyId());
                newNode.setContent(definitionContent);
                newNode.setDraftVersion(newDraftVersion);
                newNode.setName(definition.getName());
                newNode.setLocation(definition.getLocation());
                newNode.setTitleCurrentValue(titleCurrentValue);
                newNode.setTitleMap(newTitleMap[0]);
                newNode.setUserId(definition.getUserId());
                newNode.setVersion(definition.getVersion());
                newNode.setGroupId(definition.getGroupId());
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        IEditorInput editInput = getEditorInput();
                        WorkflowDefinitionEditorInput workflowEditorInput = (WorkflowDefinitionEditorInput) editInput;
                        workflowEditorInput.setWorkflowDefinitionEntry(newNode);
                        setPartName(workflowEditorInput.getName());
                        firePropertyChange(propUpdateVersion);
                    }
                });
            } catch (Exception e) {
                retval = KaleoUI.createErrorStatus("Could not save kaleo workflow entry.", e);
            }
            return retval;
        }
    };
    saveWorkflowEntry.schedule();
}
Also used : WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) IStatus(org.eclipse.core.runtime.IStatus) JSONException(org.json.JSONException) StructuredTextEditor(org.eclipse.wst.sse.ui.StructuredTextEditor) JSONException(org.json.JSONException) PartInitException(org.eclipse.ui.PartInitException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) Job(org.eclipse.core.runtime.jobs.Job) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 5 with IKaleoConnection

use of com.liferay.ide.kaleo.core.IKaleoConnection in project liferay-ide by liferay.

the class UploadNewWorkflowDefinitionAction method perform.

@Override
public void perform(Object node) {
    if (getSelectionProvider() instanceof CommonViewer && node instanceof WorkflowDefinitionsFolder) {
        IFile workspaceFile = promptForWorkspaceFile();
        if ((workspaceFile == null) || !FileUtil.exists(workspaceFile)) {
            return;
        }
        String errorMsgs = KaleoUtil.checkWorkflowDefinitionForErrors(workspaceFile);
        if (!CoreUtil.empty(errorMsgs)) {
            MessageDialog.openError(Display.getDefault().getActiveShell(), "Upload Kaleo Workflow", "Unable to upload kaleo workflow:\n\n" + errorMsgs);
            return;
        }
        WorkflowDefinitionsFolder definitionsFolder = (WorkflowDefinitionsFolder) node;
        IKaleoConnection kaleoConnection = KaleoCore.getKaleoConnection(definitionsFolder.getParent());
        Runnable runnable = new Runnable() {

            public void run() {
                CommonViewer viewer = (CommonViewer) getSelectionProvider();
                Runnable runnable = new Runnable() {

                    public void run() {
                        definitionsFolder.clearCache();
                        viewer.refresh(true);
                    }
                };
                Display.getDefault().asyncExec(runnable);
            }
        };
        Job upload = new UploadWorkflowFileJob(kaleoConnection, workspaceFile, runnable);
        upload.schedule();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IKaleoConnection(com.liferay.ide.kaleo.core.IKaleoConnection) CommonViewer(org.eclipse.ui.navigator.CommonViewer) UploadWorkflowFileJob(com.liferay.ide.kaleo.ui.util.UploadWorkflowFileJob) Job(org.eclipse.core.runtime.jobs.Job) UploadWorkflowFileJob(com.liferay.ide.kaleo.ui.util.UploadWorkflowFileJob) WorkflowDefinitionsFolder(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsFolder)

Aggregations

IKaleoConnection (com.liferay.ide.kaleo.core.IKaleoConnection)6 Job (org.eclipse.core.runtime.jobs.Job)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)3 CommonViewer (org.eclipse.ui.navigator.CommonViewer)3 WorkflowDefinitionEntry (com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry)2 WorkflowDefinitionsFolder (com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsFolder)2 UploadWorkflowFileJob (com.liferay.ide.kaleo.ui.util.UploadWorkflowFileJob)2 IFile (org.eclipse.core.resources.IFile)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 KaleoAPIException (com.liferay.ide.kaleo.core.KaleoAPIException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IDocument (org.eclipse.jface.text.IDocument)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TransferData (org.eclipse.swt.dnd.TransferData)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IViewPart (org.eclipse.ui.IViewPart)1 PartInitException (org.eclipse.ui.PartInitException)1