use of org.eclipse.gef.ui.palette.editparts.PaletteEditPart in project tesb-studio-se by Talend.
the class CamelEditorDropTargetListener method checkSelectionSource.
/**
* Routelet and context types are validated
*
* @return true if validated
*/
private boolean checkSelectionSource() {
isContextSource = false;
selectSourceList.clear();
boolean isRouteletSource = false;
LocalSelectionTransfer transfer = (LocalSelectionTransfer) getTransfer();
IStructuredSelection selection = (IStructuredSelection) transfer.getSelection();
Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
selectSourceList.add(obj);
isRouteletSource = true;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (item instanceof ContextItem) {
selectSourceList.add(obj);
isContextSource = true;
}
} else if (obj instanceof PaletteEditPart) {
selectSourceList.add(obj);
Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
if (newObject != null && newObject instanceof INode) {
if (((INode) newObject).getComponent().getComponentType() == EComponentType.JOBLET) {
selectSourceList.add(newObject);
isRouteletSource = true;
}
}
}
}
if (selectSourceList.size() == 0) {
return false;
}
if (isRouteletSource) {
List<String> routeletList = new ArrayList<String>();
for (INode node : editor.getProcess().getGraphicalNodes()) {
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
routeletList.add(node.getComponent().getName());
}
}
boolean isDuplicateRoutelet = false;
String duplicatesName = "";
for (Object object : selectSourceList) {
if (object instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) object;
if (sourceNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.PROCESS_ROUTELET) {
if (routeletList.contains(sourceNode.getProperties(EProperties.LABEL))) {
isDuplicateRoutelet = true;
//$NON-NLS-1$
duplicatesName += " ," + sourceNode.getProperties(EProperties.LABEL);
}
}
} else if (object instanceof INode) {
INode node = (INode) object;
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
if (routeletList.contains(node.getComponent().getName())) {
isDuplicateRoutelet = true;
//$NON-NLS-1$
duplicatesName += " ," + node.getComponent().getName();
}
}
}
}
if (isDuplicateRoutelet) {
//$NON-NLS-1$
MessageDialog.openInformation(//$NON-NLS-1$
editor.getEditorSite().getShell(), //$NON-NLS-1$
"Adding Routelet", //$NON-NLS-1$
"Do not allow duplicate Routelets\nRoutelet \"" + duplicatesName.substring(2) + "\" already exist.");
return false;
}
}
return true;
}
use of org.eclipse.gef.ui.palette.editparts.PaletteEditPart in project tesb-studio-se by Talend.
the class CamelEditorDropTargetListener method handleDrop.
@Override
protected void handleDrop() {
if (!checkSelectionSource()) {
return;
}
updateTargetRequest();
updateTargetEditPart();
if (selectSourceList.get(0) instanceof PaletteEditPart && getTargetRequest() instanceof CreateRequest) {
if (getTargetEditPart() instanceof ProcessPart) {
Object newObject = ((CreateRequest) getTargetRequest()).getNewObject();
if (newObject != null) {
Command command = getCommand();
if (command != null) {
execCommandStack(command);
}
}
}
return;
}
if (isContextSource) {
createContext();
} else {
if (!(getTargetEditPart() instanceof NodeContainerPart)) {
try {
createNewComponent(getCurrentEvent());
} catch (OperationCanceledException e) {
return;
}
}
}
// in case after drag/drop the editor is dirty but can not get focus
if (editor.isDirty()) {
editor.setFocus();
}
this.eraseTargetFeedback();
}
Aggregations