use of org.eclipse.swt.widgets.Canvas 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.swt.widgets.Canvas in project tdi-studio-se by Talend.
the class ComponentChooseDialog method createNewComponent.
public void createNewComponent(DropTargetEvent event1) {
boolean quickCreateInput = event1.detail == DND.DROP_LINK;
boolean quickCreateOutput = event1.detail == DND.DROP_COPY;
Iterator iterator = getSelection().iterator();
List<TempStore> list = new ArrayList<TempStore>();
List<IComponent> components = new ArrayList<IComponent>();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof RepositoryNode) {
RepositoryNode sourceNode = (RepositoryNode) obj;
if (equalsJobInCurrentEditor(sourceNode)) {
continue;
}
Item item = sourceNode.getObject().getProperty().getItem();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null && testContainerService.isTestContainerItem(item)) {
continue;
}
}
ERepositoryObjectType type = sourceNode.getObjectType();
if (!(item instanceof ConnectionItem) && !(item instanceof ProcessItem) && !(item instanceof JobletProcessItem) && !(item instanceof RulesItem) && !(item instanceof LinkRulesItem)) {
// RulesItem
return;
}
{
/**
* Remove this limitation for feature: TDI-32362, I think it should be ok, don't know why adding
* this limitation to forbid to d&d salseforce connection, I keep those code in case this behavior
* will cause some bugs when d&d salseforce connection, then maybe need to review
*/
// if (item instanceof SalesforceSchemaConnectionItem && type ==
// ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA) {
// return;
// }
}
TempStore store = new TempStore();
store.seletetedNode = sourceNode;
getAppropriateComponent(item, quickCreateInput, quickCreateOutput, store, type);
if (store.component != null) {
list.add(store);
} else {
MessageDialog.openInformation(editor.getEditorSite().getShell(), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.title"), //$NON-NLS-1$
Messages.getString("TalendEditorDropTargetListener.dngsupportdialog.content"));
}
}
org.eclipse.swt.graphics.Point swtLocation = new org.eclipse.swt.graphics.Point(event1.x, event1.y);
Canvas canvas = (Canvas) editor.getViewer().getControl();
/*
* translate to Canvas coordinate
*/
swtLocation = canvas.toControl(swtLocation);
org.eclipse.swt.graphics.Point size = canvas.getSize();
/*
* translate to Viewport coordinate with zoom
*/
org.eclipse.draw2d.geometry.Point draw2dPosition = new org.eclipse.draw2d.geometry.Point(swtLocation.x, swtLocation.y);
/*
* calcule the view port position. Take into acounte the scroll position
*/
ProcessPart part = (ProcessPart) editor.getViewer().getRootEditPart().getRoot().getChildren().get(0);
IFigure targetFigure = part.getFigure();
translateAbsolateToRelative(targetFigure, draw2dPosition);
//$NON-NLS-1$
String lastUniqname = "";
// creates every node
for (TempStore store : list) {
RepositoryNode selectedNode = store.seletetedNode;
IComponent element = store.component;
if (!components.contains(element)) {
components.add(element);
}
Node node = new Node(element);
// for bug4564(metadata label format)
// IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
// if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
// node.setPropertyValue(EParameterName.LABEL.getName(), selectedNode.getObject().getLabel());
// }
IPreferenceStore preferenceStore = DesignerPlugin.getDefault().getPreferenceStore();
if (preferenceStore.getBoolean(TalendDesignerPrefConstants.USE_REPOSITORY_NAME)) {
String LabelValue = null;
RepositoryNode repositoryNode = null;
repositoryNode = (RepositoryNode) getSelection().getFirstElement();
// dnd a table
IElementParameter dbTableParam = node.getElementParameterFromField(EParameterFieldType.DBTABLE);
boolean hasDbTableField = dbTableParam != null;
if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE && repositoryNode.getObject() != null && repositoryNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem && hasDbTableField) {
LabelValue = DesignerUtilities.getParameterVar(dbTableParam.getName());
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_MR || repositoryNode.getObjectType() == ERepositoryObjectType.PROCESS_STORM) {
// dnd a job
LabelValue = DesignerUtilities.getParameterVar(EParameterName.PROCESS);
} else if (repositoryNode.getObjectType() == ERepositoryObjectType.JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_JOBLET || repositoryNode.getObjectType() == ERepositoryObjectType.SPARK_STREAMING_JOBLET) {
LabelValue = element.getName();
} else if (CorePlugin.getDefault().getDesignerCoreService().getPreferenceStore(TalendDesignerPrefConstants.DEFAULT_LABEL).equals(node.getPropertyValue(EParameterName.LABEL.getName()))) {
// dnd a default
LabelValue = selectedNode.getObject().getLabel();
}
if (LabelValue != null) {
node.setPropertyValue(EParameterName.LABEL.getName(), LabelValue);
}
}
processSpecificDBTypeIfSameProduct(store.componentName, node);
NodeContainer nc = ((Process) node.getProcess()).loadNodeContainer(node, false);
;
// create component on link
boolean executed = false;
if (getSelection().size() == 1 && getTargetEditPart() instanceof SubjobContainerPart) {
executed = createComponentOnLink(node, draw2dPosition);
}
if (!executed) {
// create the node on the design sheet
execCommandStack(new CreateNodeContainerCommand((Process) editor.getProcess(), nc, draw2dPosition));
}
// initialize the propertiesView
CompoundCommand cc = new CompoundCommand();
createRefreshingPropertiesCommand(cc, selectedNode, node);
execCommandStack(cc);
// for (Command command : commands) {
// }
propaHadoopCfgChanges(selectedNode);
draw2dPosition = draw2dPosition.getCopy();
draw2dPosition.x += TalendEditor.GRID_SIZE;
draw2dPosition.y += TalendEditor.GRID_SIZE;
node.checkNode();
lastUniqname = node.getUniqueName();
}
// setselecte(part, lastUniqname);
}
// Shell shell = Display.getCurrent().getActiveShell();
// ModulesInstallerUtil.installModules(new Shell(shell), components);
}
use of org.eclipse.swt.widgets.Canvas 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);
}
use of org.eclipse.swt.widgets.Canvas in project dbeaver by serge-rider.
the class ERDOutlinePage method createControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
// create canvas and lws
overview = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(overview);
// create thumbnail
thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
thumbnail.setBorder(new MarginBorder(3));
thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
lws.setContents(thumbnail);
}
use of org.eclipse.swt.widgets.Canvas in project translationstudio8 by heartsome.
the class NatCombo method createTextControl.
private void createTextControl() {
text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
text.setLayoutData(gridData);
text.forceFocus();
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
showDropdownControl();
int selectionIndex = dropdownList.getSelectionIndex();
selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
if (selectionIndex < 0) {
selectionIndex = 0;
}
dropdownList.select(selectionIndex);
text.setText(dropdownList.getSelection()[0]);
}
}
});
iconImage = GUIHelper.getImage("down_2");
final Canvas iconCanvas = new Canvas(this, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle iconImageBounds = iconImage.getBounds();
return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
}
};
gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
iconCanvas.setLayoutData(gridData);
iconCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
Rectangle iconCanvasBounds = iconCanvas.getBounds();
Rectangle iconImageBounds = iconImage.getBounds();
int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
Color originalFg = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
gc.setForeground(originalFg);
}
});
iconCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showDropdownControl();
}
});
}
Aggregations