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;
}
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);
}
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);
}
}
}
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();
}
}
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();
}
Aggregations