use of org.eclipse.gef.requests.CreationFactory in project dbeaver by serge-rider.
the class ERDEditorPart method createPaletteRoot.
public PaletteRoot createPaletteRoot() {
// create root
PaletteRoot paletteRoot = new PaletteRoot();
paletteRoot.setLabel("Entity Diagram");
{
// a group of default control tools
PaletteDrawer controls = new PaletteDrawer("Tools", DBeaverIcons.getImageDescriptor(UIIcon.CONFIGURATION));
paletteRoot.add(controls);
// the selection tool
ToolEntry selectionTool = new SelectionToolEntry();
controls.add(selectionTool);
// use selection tool as default entry
paletteRoot.setDefaultEntry(selectionTool);
// the marquee selection tool
controls.add(new MarqueeToolEntry());
if (!isReadOnly()) {
// separator
PaletteSeparator separator = new PaletteSeparator("tools");
separator.setUserModificationPermission(PaletteEntry.PERMISSION_NO_MODIFICATION);
controls.add(separator);
final ImageDescriptor connectImage = ERDActivator.getImageDescriptor("icons/connect.png");
controls.add(new ConnectionCreationToolEntry("Connection", "Create Connection", null, connectImage, connectImage));
final ImageDescriptor noteImage = ERDActivator.getImageDescriptor("icons/note.png");
controls.add(new CreationToolEntry("Note", "Create Note", new CreationFactory() {
@Override
public Object getNewObject() {
return new ERDNote("Note");
}
@Override
public Object getObjectType() {
return RequestConstants.REQ_CREATE;
}
}, noteImage, noteImage));
}
}
return paletteRoot;
}
use of org.eclipse.gef.requests.CreationFactory in project tdi-studio-se by Talend.
the class TalendEditorComponentProposalProvider method getProposals.
/**
* Return an array of Objects representing the valid content proposals for a field.
*
* @param contents the current contents of the field (only consulted if filtering is set to <code>true</code>)
* @param position the current cursor position within the field (ignored)
* @return the array of Objects that represent valid proposals for the field given its current content.
*/
@Override
public IContentProposal[] getProposals(String contents, int position) {
List<IComponent> relatedComponent = TalendEditorPaletteFactory.getRelatedComponents(componentsFactory, contents);
if (componentAssistant != null) {
relatedComponent = componentAssistant.filterComponents(relatedComponent);
}
proposalList.clear();
// add joblet components in joblet editor.
List<PaletteEntry> extraPaletteEntry = ComponentPaletteUtilities.getExtraPaletteEntry();
if (extraPaletteEntry != null) {
for (PaletteEntry entry : extraPaletteEntry) {
if (entry != null && entry.isVisible() && entry instanceof TalendCreationToolEntry) {
TalendCreationToolEntry tool = (TalendCreationToolEntry) entry;
CreationFactory creationFactory = tool.getFactory();
if (creationFactory != null && creationFactory instanceof PaletteComponentFactory) {
PaletteComponentFactory componentFactory = (PaletteComponentFactory) creationFactory;
proposalList.add(new ComponentContentProposal(componentFactory.getComponent()));
}
}
}
}
if (relatedComponent != null && !relatedComponent.isEmpty()) {
Iterator<IComponent> iter = relatedComponent.iterator();
while (iter.hasNext()) {
IComponent component = iter.next();
// proposalList.add(new ComponentContentProposal(component.getName(), component.getLongName(),
// component));
proposalList.add(new ComponentContentProposal(component));
}
}
/**
* Always add Note
*/
//$NON-NLS-1$
DummyComponent noteComponent = new DummyComponent("Note");
noteComponent.setIcon16(ImageProvider.getImageDesc(ECoreImage.NOTE_SMALL_ICON));
//$NON-NLS-1$
noteComponent.setOriginalFamilyName("Misc");
proposalList.add(new ComponentContentProposal(noteComponent));
return proposalList.toArray(new IContentProposal[0]);
}
use of org.eclipse.gef.requests.CreationFactory in project tdi-studio-se by Talend.
the class ConnectionCreateAction method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
IMetadataTable meta = null;
IMetadataTable newMetadata = null;
String connectionName = null;
if (getSelectedObjects().isEmpty()) {
return;
}
List parts = getSelectedObjects();
if (parts.size() == 1) {
Object o = parts.get(0);
if (!(o instanceof NodePart)) {
return;
}
nodePart = (NodePart) o;
} else {
return;
}
Node node = (Node) nodePart.getModel();
if (curNodeConnector.isMultiSchema()) {
if (getText().equals(getNewOutputMenuName())) {
// boolean nameOk = false;
// while (!nameOk) {
//
// if (node.isELTComponent()) {
// connectionName = "Default";
// } else {
// connectionName = askForConnectionName(node.getLabel(), connectionName);
// }
// if (connectionName.equals("")) { //$NON-NLS-1$
// return;
// }
// if (connecType.equals(EConnectionType.TABLE) ||
// node.getProcess().checkValidConnectionName(connectionName)) {
// nameOk = true;
// } else {
// String message = Messages.getString("ConnectionCreateAction.errorCreateConnectionName",
// connectionName); //$NON-NLS-1$
// MessageDialog.openError(getWorkbenchPart().getSite().getShell(), Messages
// .getString("ConnectionCreateAction.error"), message); //$NON-NLS-1$
// }
// }
//
// if (connecType.equals(EConnectionType.TABLE)) {
// meta = new MetadataTable();
// meta.setTableName(connectionName);
// meta.setLabel(connectionName);
// // meta.setTableId(node.getMetadataList().size());
// newMetadata = meta;
// } else {
// boolean metaExist = false;
// for (int i = 0; i < node.getMetadataList().size(); i++) {
// if ((node.getMetadataList().get(i)).getTableName().equals(connectionName)) {
// metaExist = true;
// }
// }
// if (!metaExist) {
// meta = new MetadataTable();
// meta.setTableName(connectionName);
// newMetadata = meta;
// }
// }
} else {
String tableName;
// int tableId = -1;
if (connecType == EConnectionType.TABLE) {
int end = getText().length() - 1;
//$NON-NLS-1$
int start = getText().lastIndexOf("(") + 1;
tableName = getText().substring(start, end);
// table = Integer.parseInt(stringId);
// tableName = getText().substring(0, start - 2);
meta = node.getMetadataTable(tableName);
// meta = (IMetadataTable) node.getMetadataList().get(tableId);
connectionName = meta.getLabel();
} else {
tableName = getText();
// tableId = -1;
meta = node.getMetadataTable(tableName);
// for (int i = 0; i < node.getMetadataList().size(); i++) {
// IMetadataTable table = (IMetadataTable) node.getMetadataList().get(i);
// if (table.getTableName().equals(tableName)) {
// meta = (IMetadataTable) node.getMetadataList().get(i);
// }
// }
connectionName = meta.getTableName();
}
}
// for built-in only:
if (meta != null) {
meta.setAttachedConnector(curNodeConnector.getName());
}
} else {
if (connecType == EConnectionType.TABLE) {
if (getText().equals(getDefaultTableName())) {
//$NON-NLS-1$
int end = getText().lastIndexOf("(") - 1;
int start = 0;
if (end >= start) {
connectionName = getText().substring(start, end);
meta = node.getMetadataList().get(0);
meta.setAttachedConnector(curNodeConnector.getName());
} else if (getText().endsWith(".")) {
connectionName = askForConnectionName(node.getLabel(), null);
if (connectionName != null && !"".equals(connectionName)) {
connectionName = getText() + connectionName;
}
meta = node.getMetadataList().get(0);
meta.setAttachedConnector(curNodeConnector.getName());
}
} else if (getText().equals(getNewOutputMenuName()) && getDefaultTableName() != null) {
if (node.getComponent().getName().equals("tELTOracleInput")) {
//$NON-NLS-1$
connectionName = askForConnectionNameAndSchema(node.getLabel(), null);
} else {
connectionName = askForConnectionName(node.getLabel(), null);
}
} else {
// if (node.isELTComponent() && node.getComponentName().endsWith("Input"))
if (node.getComponent().getName().equals("tELTOracleInput")) {
//$NON-NLS-1$
connectionName = askForConnectionNameAndSchema(node.getLabel(), getDefaultSchemaName());
} else {
connectionName = askForConnectionName(node.getLabel(), null);
}
}
} else {
if (connecType.hasConnectionCategory(IConnectionCategory.FLOW)) {
connectionName = node.getProcess().generateUniqueConnectionName(Process.DEFAULT_ROW_CONNECTION_NAME);
} else if (connecType.hasConnectionCategory(IConnectionCategory.CAMEL)) {
connectionName = ConnectionUtil.generateUniqueConnectionName(connecType, node.getProcess(), curNodeConnector);
} else {
connectionName = curNodeConnector.getLinkName();
}
}
if (node.getMetadataList().size() == 0) {
meta = null;
} else {
meta = node.getMetadataFromConnector(curNodeConnector.getName());
}
}
/**
* Create a mouse down event that thinks it is over the blob and dispatch it. This is a bit of a fudge to mimic
* what the user ought to do.
*/
Point point = null;
point = nodePart.getFigure().getClientArea().getCenter();
Point p = point;
nodePart.getFigure().translateToAbsolute(p);
Canvas canvas = (Canvas) nodePart.getViewer().getControl();
Event event = new Event();
event.button = 1;
event.count = 0;
event.detail = 0;
event.end = 0;
event.height = 0;
event.keyCode = 0;
event.start = 0;
event.stateMask = 0;
// any old time... doesn't matter
event.time = 9516624;
event.type = 3;
event.widget = canvas;
event.width = 0;
event.x = p.x + 3;
event.y = p.y + 3;
/**
* Set the connection tool to be the current tool
*/
listArgs = new ArrayList<Object>();
if (connecType.equals(EConnectionType.FLOW_MAIN) || connecType.equals(EConnectionType.FLOW_REF) || connecType.equals(EConnectionType.TABLE)) {
if (meta == null) {
listArgs.add(null);
} else {
listArgs.add(meta.getTableName());
}
} else {
listArgs.add(node.getUniqueName());
}
String baseName = node.getConnectionName();
String fromConnectionName = null;
if (node.getProcess().checkValidConnectionName(baseName)) {
fromConnectionName = node.getProcess().generateUniqueConnectionName(baseName);
}
if (fromConnectionName != null && connecType.hasConnectionCategory(IConnectionCategory.FLOW) && node.getProcess().checkValidConnectionName(fromConnectionName, false) && !curNodeConnector.isMultiSchema()) {
listArgs.add(fromConnectionName);
} else {
listArgs.add(connectionName);
}
listArgs.add(newMetadata);
TalendConnectionCreationTool myConnectTool = new TalendConnectionCreationTool(new CreationFactory() {
@Override
public Object getNewObject() {
return listArgs;
}
@Override
public Object getObjectType() {
return curNodeConnector.getName();
}
}, true);
myConnectTool.performConnectionStartWith(nodePart);
nodePart.getViewer().getEditDomain().setActiveTool(myConnectTool);
canvas.notifyListeners(3, event);
}
use of org.eclipse.gef.requests.CreationFactory in project tdi-studio-se by Talend.
the class TalendConnectionHandle method createDragTracker.
/*
* (non-Javadoc)
*
* @see org.eclipse.gef.handles.AbstractHandle#createDragTracker()
*/
@Override
protected DragTracker createDragTracker() {
if (this.mainConnector == null) {
this.mainConnector = new NodeConnectorTool(nodePart).getConnector();
}
if (this.mainConnector == null) {
return null;
}
final List<Object> listArgs = new ArrayList<Object>();
listArgs.add(null);
listArgs.add(null);
listArgs.add(null);
TalendCreateConnectionTool myConnectTool = new TalendCreateConnectionTool(new CreationFactory() {
@Override
public Object getNewObject() {
return listArgs;
}
@Override
public Object getObjectType() {
// should get the connector at realtime
mainConnector = new NodeConnectorTool(nodePart).getConnector();
if (mainConnector == null) {
// if no connector is available, maybe can return "on componnet ok" connector to avoid NPE
Node node = (Node) nodePart.getModel();
mainConnector = node.getConnectorFromType(EConnectionType.ON_COMPONENT_OK);
// specify the connection name
listArgs.set(1, mainConnector.getLinkName());
} else {
// no need to specify the connection name
listArgs.set(1, null);
}
return mainConnector.getName();
}
}, nodePart);
return myConnectTool;
}
use of org.eclipse.gef.requests.CreationFactory in project tdi-studio-se by Talend.
the class CreateRelationAction method run.
@Override
public void run() {
if (getSelectedObjects().isEmpty()) {
return;
}
List parts = getSelectedObjects();
if (parts.size() == 1) {
Object o = parts.get(0);
if (!(o instanceof ColumnPart)) {
return;
}
columnPart = (ColumnPart) o;
} else {
return;
}
/**
* Create a mouse down event that thinks it is over the blob and dispatch it. This is a bit of a fudge to mimic
* what the user ought to do.
*/
Point point = null;
point = columnPart.getFigure().getClientArea().getCenter();
Point p = point;
columnPart.getFigure().translateToAbsolute(p);
Canvas canvas = (Canvas) columnPart.getViewer().getControl();
Event event = new Event();
event.button = 1;
event.count = 0;
event.detail = 0;
event.end = 0;
event.height = 0;
event.keyCode = 0;
event.start = 0;
event.stateMask = 0;
// any old time... doesn't matter
event.time = 9516624;
event.type = 3;
event.widget = canvas;
event.width = 0;
event.x = p.x + 3;
event.y = p.y + 3;
WhereConnectionCreationTool tool = new WhereConnectionCreationTool(new CreationFactory() {
public Object getNewObject() {
return null;
}
public Object getObjectType() {
return null;
}
});
columnPart.getViewer().getEditDomain().setActiveTool(tool);
canvas.notifyListeners(3, event);
}
Aggregations