Search in sources :

Example 1 with WorkflowDefinitionEntry

use of com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry in project liferay-ide by liferay.

the class WorkflowProjectAdapterService method convert.

@Override
public <A> A convert(Object object, Class<A> adapterType) {
    A retval = null;
    if (IProject.class.equals(adapterType)) {
        ISapphirePart sapphirePart = context().find(ISapphirePart.class);
        WorkflowDefinition workflowDefinition = sapphirePart.getLocalModelElement().nearest(WorkflowDefinition.class);
        IFile file = workflowDefinition.adapt(IFile.class);
        if (file != null) {
            retval = adapterType.cast(file.getProject());
        } else {
            // create support project
            WorkflowSupportManager workflowSupportManager = KaleoCore.getDefault().getWorkflowSupportManager();
            IEditorInput editorInput = workflowDefinition.adapt(IEditorInput.class);
            if (editorInput instanceof WorkflowDefinitionEditorInput) {
                WorkflowDefinitionEditorInput workflowInput = (WorkflowDefinitionEditorInput) editorInput;
                WorkflowDefinitionEntry workflowEntry = workflowInput.getWorkflowDefinitionEntry();
                IServer server = workflowEntry.getParent().getParent();
                workflowSupportManager.setCurrentServer(server);
            }
            IJavaProject supportProject = workflowSupportManager.getSupportProject();
            retval = adapterType.cast(supportProject.getProject());
        }
    }
    return retval;
}
Also used : WorkflowDefinitionEditorInput(com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditorInput) WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) IServer(org.eclipse.wst.server.core.IServer) IFile(org.eclipse.core.resources.IFile) IJavaProject(org.eclipse.jdt.core.IJavaProject) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) WorkflowSupportManager(com.liferay.ide.kaleo.core.WorkflowSupportManager) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with WorkflowDefinitionEntry

use of com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry in project liferay-ide by liferay.

the class AbstractWorkflowDefinitionAction method selectionChanged.

@SuppressWarnings("rawtypes")
public void selectionChanged(IStructuredSelection sel) {
    if (sel.isEmpty()) {
        setEnabled(false);
        return;
    }
    boolean enabled = false;
    Iterator iterator = sel.iterator();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof WorkflowDefinitionEntry) {
            WorkflowDefinitionEntry node = (WorkflowDefinitionEntry) obj;
            if (accept(node)) {
                enabled = true;
            }
        } else if (obj instanceof WorkflowDefinitionsFolder) {
            WorkflowDefinitionsFolder node = (WorkflowDefinitionsFolder) obj;
            if (accept(node)) {
                enabled = true;
            }
        } else {
            setEnabled(false);
            return;
        }
    }
    setEnabled(enabled);
}
Also used : WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) Iterator(java.util.Iterator) WorkflowDefinitionsFolder(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsFolder)

Example 3 with WorkflowDefinitionEntry

use of com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry in project liferay-ide by liferay.

the class EditWorkflowDefinitionAction method perform.

@Override
public void perform(Object entry) {
    if (entry instanceof WorkflowDefinitionEntry) {
        WorkflowDefinitionEntry workflowEntry = (WorkflowDefinitionEntry) entry;
        IWorkbench workBench = PlatformUI.getWorkbench();
        IWorkbenchWindow wbWindow = workBench.getActiveWorkbenchWindow();
        IWorkbenchPage page = wbWindow.getActivePage();
        IEditorPart[] dirtyEditors = page.getDirtyEditors();
        for (IEditorPart dirtyEditor : dirtyEditors) {
            IEditorInput editorInput = dirtyEditor.getEditorInput();
            if (editorInput instanceof WorkflowDefinitionEditorInput) {
                WorkflowDefinitionEditorInput dirtyWorkflowEditorInput = (WorkflowDefinitionEditorInput) editorInput;
                boolean opened = dirtyWorkflowEditorInput.getName().contains(workflowEntry.getName());
                if (opened) {
                    IEditorSite editorSite = dirtyEditor.getEditorSite();
                    boolean saveOld = MessageDialog.openQuestion(editorSite.getShell(), "Save " + dirtyWorkflowEditorInput.getName(), "Do you want to save contents of this editor?");
                    page.closeEditor(dirtyEditor, saveOld);
                }
            }
        }
        try {
            WorkflowDefinitionEditorInput editorInput = new WorkflowDefinitionEditorInput(workflowEntry);
            IEditorPart editor = page.openEditor(editorInput, WorkflowDefinitionEditor.EDITOR_ID, true, IWorkbenchPage.MATCH_INPUT);
            editor.addPropertyListener(new IPropertyListener() {

                public void propertyChanged(Object source, int propId) {
                    if (source.equals(editor) && (propId == WorkflowDefinitionEditor.propUpdateVersion)) {
                        workflowEntry.getParent().clearCache();
                        ((CommonViewer) EditWorkflowDefinitionAction.this.getSelectionProvider()).refresh(true);
                    }
                }
            });
        } catch (PartInitException pie) {
            KaleoUI.logError("Error opening kaleo workflow editor.", pie);
        }
    }
}
Also used : WorkflowDefinitionEntry(com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) IPropertyListener(org.eclipse.ui.IPropertyListener) IWorkbench(org.eclipse.ui.IWorkbench) WorkflowDefinitionEditorInput(com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IEditorSite(org.eclipse.ui.IEditorSite)

Example 4 with WorkflowDefinitionEntry

use of com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry 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 5 with WorkflowDefinitionEntry

use of com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry 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)

Aggregations

WorkflowDefinitionEntry (com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionEntry)5 IEditorInput (org.eclipse.ui.IEditorInput)3 IKaleoConnection (com.liferay.ide.kaleo.core.IKaleoConnection)2 WorkflowDefinitionEditorInput (com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditorInput)2 WorkflowDefinitionsFolder (com.liferay.ide.kaleo.ui.navigator.WorkflowDefinitionsFolder)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Job (org.eclipse.core.runtime.jobs.Job)2 PartInitException (org.eclipse.ui.PartInitException)2 KaleoAPIException (com.liferay.ide.kaleo.core.KaleoAPIException)1 WorkflowSupportManager (com.liferay.ide.kaleo.core.WorkflowSupportManager)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 Iterator (java.util.Iterator)1 IFile (org.eclipse.core.resources.IFile)1 IStatus (org.eclipse.core.runtime.IStatus)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IDocument (org.eclipse.jface.text.IDocument)1 ISapphirePart (org.eclipse.sapphire.ui.ISapphirePart)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IEditorSite (org.eclipse.ui.IEditorSite)1 IPropertyListener (org.eclipse.ui.IPropertyListener)1