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