use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class ProcessExplorerDropTarget method handleDropWorkflowAsset.
private boolean handleDropWorkflowAsset(String assetInfo, WorkflowPackage targetPackage, int operation) {
if (!targetPackage.getProject().checkRequiredVersion(5, 0)) {
String msg = "Packaging of Definition Documents (such as scripts and pages) is only supported for MDWFramework 5.0 and later.";
MessageDialog.openError(getViewer().getControl().getShell(), "Package Def Doc", msg);
return false;
}
Long assetId = getWorkflowAssetId(assetInfo);
WorkflowProject workflowProject = targetPackage.getProject();
WorkflowPackage sourcePackage = workflowProject.getPackage(getPackageName(assetInfo));
DesignerProxy designerProxy = workflowProject.getDesignerProxy();
if (operation == DND.DROP_COPY) {
WorkflowAsset existing = workflowProject.getAsset(assetId);
CopyDialog copyDialog = new CopyDialog(getViewer().getControl().getShell(), existing, existing.getName(), String.valueOf(existing.getVersion()), targetPackage);
if (copyDialog.open() == Dialog.OK) {
String newName = copyDialog.getNewName();
if (!existing.isLoaded())
existing.load();
WorkflowAsset newCopy;
try {
// try and use reflection to make it the correct type
Constructor<? extends WorkflowAsset> ctor = existing.getClass().getConstructor(existing.getClass());
newCopy = ctor.newInstance(existing);
} catch (Exception ex) {
PluginMessages.log(ex);
newCopy = new WorkflowAsset(existing);
}
newCopy.setName(newName);
newCopy.setVersion(1);
newCopy.setPackage(targetPackage);
try {
designerProxy.createNewWorkflowAsset(newCopy, true);
} catch (Exception ex) {
PluginMessages.uiError(ex, "Copy " + existing.getTitle(), existing.getProject());
}
newCopy.addElementChangeListener(workflowProject);
newCopy.fireElementChangeEvent(ChangeType.ELEMENT_CREATE, newCopy);
WorkflowAssetFactory.registerAsset(newCopy);
((TreeViewer) getViewer()).refresh(targetPackage, true);
return true;
}
return false;
} else if (operation == DND.DROP_MOVE) {
// don't allow multiple versions of the same asset in a package
if (!targetPackage.isDefaultPackage()) {
WorkflowAsset asset = workflowProject.getAsset(assetId);
if (targetPackage.getAsset(asset.getName()) != null) {
MessageDialog.openError(MdwPlugin.getShell(), "Asset Exists", "Asset '" + asset.getName() + "' already exists in package '" + targetPackage.getName() + "'.");
return false;
}
}
if (targetPackage.isDefaultPackage()) {
designerProxy.removeWorkflowAssetFromPackage(assetId, sourcePackage);
} else {
assetId = designerProxy.moveWorkflowAssetToPackage(assetId, targetPackage);
}
((TreeViewer) getViewer()).refresh(targetPackage.getProject(), true);
WorkflowAssetFactory.registerAsset(workflowProject.getAsset(assetId));
return true;
} else {
return false;
}
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class ParameterizedCombo method fillParamCombo.
private void fillParamCombo(String[] types) {
paramCombo.removeAll();
Comparator<WorkflowElement> comparator = new Comparator<WorkflowElement>() {
public int compare(WorkflowElement we1, WorkflowElement we2) {
return we1.getName().compareTo(we2.getName());
}
};
List<WorkflowAsset> assets = workflowProject.getAssetList(Arrays.asList(types));
Map<WorkflowPackage, List<WorkflowAsset>> packageAssets = new TreeMap<>();
for (WorkflowAsset asset : assets) {
List<WorkflowAsset> assetsForPkg = packageAssets.get(asset.getPackage());
if (assetsForPkg == null) {
assetsForPkg = new ArrayList<>();
packageAssets.put(asset.getPackage(), assetsForPkg);
}
assetsForPkg.add(asset);
}
for (WorkflowPackage pkg : packageAssets.keySet()) {
CTreeComboItem packageItem = new CTreeComboItem(paramCombo, SWT.NONE);
packageItem.setText(pkg.getName());
packageItem.setImage(pkg.getIconImage());
List<WorkflowAsset> assetsForPkg = packageAssets.get(pkg);
Collections.sort(assetsForPkg, comparator);
for (WorkflowAsset assetForPkg : assetsForPkg) {
CTreeComboItem assetItem = new CTreeComboItem(packageItem, SWT.NONE);
assetItem.setText(assetForPkg.getName());
assetItem.setImage(assetForPkg.getIconImage());
}
}
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class ParameterizedCombo method assetFromAttr.
public WorkflowAsset assetFromAttr(String attrValue) {
if (attrValue == null || attrValue.isEmpty() || attrValue.startsWith("$")) {
return null;
}
int slashIdx = attrValue.indexOf('/');
if (slashIdx <= 0) {
// prefer asset in same package
WorkflowAsset pkgDoc = workflowElement.getPackage().getAsset(attrValue);
if (pkgDoc != null)
return pkgDoc;
else
return workflowProject.getAsset(attrValue);
} else {
String pkgName = attrValue.substring(0, slashIdx);
WorkflowPackage pkg = workflowProject.getPackage(pkgName);
if (pkg == null)
return null;
else
return pkg.getAsset(attrValue.substring(slashIdx + 1));
}
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class ParameterizedCombo method createParamCombo.
private void createParamCombo() {
paramCombo = new CTreeCombo(this, SWT.BORDER | SWT.FULL_SELECTION);
GridData gd = new GridData(GridData.BEGINNING);
gd.widthHint = 200;
gd.heightHint = 16;
paramCombo.setLayoutData(gd);
paramCombo.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
CTreeComboItem[] selItems = paramCombo.getSelection();
if (selItems.length == 1) {
CTreeComboItem selItem = selItems[0];
if (selItem.getItemCount() != 0) {
// ignore package selection
paramCombo.setSelection(new CTreeComboItem[0]);
} else {
try {
Thread.sleep(200);
} catch (InterruptedException ex) {
}
// set the definition doc
WorkflowPackage pkg = workflowProject.getPackage(selItem.getParentItem().getText());
if (pkg == null) {
paramAsset = null;
} else {
paramAsset = pkg.getAsset(selItem.getText());
}
paramLink.setText(getParamLinkLabel());
fireModify(new ModifyEvent(event));
paramCombo.dropDown(false);
}
}
}
});
paramCombo.addListener(SWT.Modify, new Listener() {
public void handleEvent(Event event) {
if (paramCombo.getSelection().length == 0) {
// something was typed in the combo instead of selected
paramAsset = assetFromAttr(paramCombo.getText().trim());
paramLink.setText(getParamLinkLabel());
String oldVal = workflowElement.getAttribute(paramLabel.getText());
String newVal;
if (paramCombo.getText().startsWith("$"))
newVal = paramCombo.getText().trim();
else
newVal = paramAsset == null ? paramCombo.getText() : attrFromAsset(paramAsset, false);
boolean changed = oldVal == null ? newVal != null && newVal.length() > 0 : !oldVal.equals(newVal);
if (changed && !suppressFire)
fireModify(new ModifyEvent(event));
}
}
});
paramLink = new Link(this, SWT.SINGLE);
gd = new GridData(GridData.BEGINNING);
gd.widthHint = 75;
paramLink.setLayoutData(gd);
paramLink.setText(getParamLinkLabel());
paramLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (paramAsset == null) {
String[] paramTypes = valueConverter.getOptionParam(getValue()).getTypes();
paramAsset = createParamAsset(paramTypes);
fillParamCombo(paramTypes);
if (paramAsset != null) {
paramCombo.setText(paramAsset.getName());
fireModify(new ModifyEvent(new Event()));
}
} else {
openParamAsset();
}
}
});
}
use of com.centurylink.mdw.plugin.designer.model.WorkflowPackage in project mdw-designer by CenturyLinkCloud.
the class WorkflowProject method findArchivedPackages.
/**
* Returns all top-level archived (non-latest) packages, populated with
* their descendants which include the appropriate process versions. Uses
* 10% of progressMonitor.
*/
private Folder findArchivedPackages(ProgressMonitor progressMonitor, boolean visiblePkgsOnly) {
CodeTimer timer = new CodeTimer("findAuthorizedArchivedPackages()");
if (progressMonitor != null)
progressMonitor.subTask("Organizing packages");
Folder archivedPkgFolder = new Folder("Archive", this);
archivedPkgFolder.setIcon("archive.gif");
List<WorkflowPackage> topLevelArchivedPackageList = new ArrayList<>();
List<WorkflowPackage> allArchivedPackages = new ArrayList<>();
for (PackageVO packageVO : getDataAccess().getPackages(false)) {
if (isShowDefaultPackage() || !packageVO.isDefaultPackage()) {
WorkflowPackage potentialArchived = new WorkflowPackage(this, packageVO);
if (!getTopLevelPackages().contains(potentialArchived)) {
potentialArchived.setArchived(true);
potentialArchived.setProcesses(findProcesses(potentialArchived));
potentialArchived.setAssets(findWorkflowAssets(potentialArchived));
potentialArchived.setActivityImpls(findActivityImplementors(potentialArchived));
potentialArchived.setExternalEvents(findExternalEvents(potentialArchived));
potentialArchived.setTaskTemplates(findTaskTemplates(potentialArchived));
allArchivedPackages.add(potentialArchived);
}
}
}
// organize the package version hierarchy
Map<String, WorkflowPackage> topLevelArchivedPackages = new HashMap<>();
for (WorkflowPackage archivedPackage : allArchivedPackages) {
WorkflowPackage topLevel = topLevelArchivedPackages.get(archivedPackage.getName());
if ((!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible())) && (topLevel == null || archivedPackage.getPackageVO().getVersion() > topLevel.getPackageVO().getVersion()))
topLevelArchivedPackages.put(archivedPackage.getName(), archivedPackage);
}
for (WorkflowPackage topLevelArchivedPackage : topLevelArchivedPackages.values()) {
for (WorkflowPackage archivedPackage : allArchivedPackages) {
if (topLevelArchivedPackage.getName().equals(archivedPackage.getName()) && (!visiblePkgsOnly || (visiblePkgsOnly && archivedPackage.isVisible()))) {
if (topLevelArchivedPackage.equals(archivedPackage)) {
// clone top-level process for first child
WorkflowPackage firstChild = new WorkflowPackage(topLevelArchivedPackage);
firstChild.setArchived(true);
firstChild.setTopLevelVersion(topLevelArchivedPackage);
firstChild.setProcesses(topLevelArchivedPackage.getProcesses());
firstChild.setAssets(topLevelArchivedPackage.getAssets());
firstChild.setActivityImpls(topLevelArchivedPackage.getActivityImpls());
firstChild.setExternalEvents(topLevelArchivedPackage.getExternalEvents());
firstChild.setTaskTemplates(topLevelArchivedPackage.getTaskTemplates());
topLevelArchivedPackage.addDescendantPackageVersion(firstChild);
} else {
archivedPackage.setTopLevelVersion(topLevelArchivedPackage);
topLevelArchivedPackage.addDescendantPackageVersion(archivedPackage);
}
}
}
topLevelArchivedPackageList.add(topLevelArchivedPackage);
topLevelArchivedPackage.setArchivedFolder(archivedPkgFolder);
}
Collections.sort(topLevelArchivedPackageList);
if (isShowDefaultPackage()) {
// add unpackaged (default package)
PackageVO defaultPackageVO = new PackageVO();
defaultPackageVO.setPackageId(Long.valueOf(0));
defaultPackageVO.setPackageName(PackageVO.DEFAULT_PACKAGE_NAME);
archivedDefaultPackage = new WorkflowPackage(this, defaultPackageVO);
archivedDefaultPackage.setProcesses(findUnpackagedProcesses());
archivedDefaultPackage.setChildFolders(findUnpackagedAssetFolders());
archivedDefaultPackage.setArchived(true);
topLevelArchivedPackageList.add(0, archivedDefaultPackage);
}
List<WorkflowElement> children = new ArrayList<>();
children.addAll(topLevelArchivedPackageList);
archivedPkgFolder.setChildren(children);
if (progressMonitor != null)
progressMonitor.progress(10);
timer.stopAndLog();
return archivedPkgFolder;
}
Aggregations