use of org.eclipse.swt.custom.StyledText in project tdi-studio-se by Talend.
the class StandAloneTalendJavaEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
super.init(site, input);
Bundle bundle = FrameworkUtil.getBundle(StandAloneTalendJavaEditor.class);
lockService = bundle.getBundleContext().registerService(EventHandler.class.getName(), new EventHandler() {
@Override
public void handleEvent(Event event) {
String lockTopic = Constant.REPOSITORY_ITEM_EVENT_PREFIX + Constant.ITEM_LOCK_EVENT_SUFFIX;
if (lockTopic.equals(event.getTopic())) {
if (!isEditable) {
Object o = event.getProperty(Constant.ITEM_EVENT_PROPERTY_KEY);
if (o instanceof FileItem) {
boolean isTheCorrectEditor = false;
Property property = ((FileItem) o).getProperty();
if (property != null) {
String eventItemId = property.getId();
//$NON-NLS-1$
String currentOpenedItemId = "";
if (rEditorInput != null) {
currentOpenedItemId = rEditorInput.getId();
}
isTheCorrectEditor = currentOpenedItemId.equals(eventItemId);
}
if (!isTheCorrectEditor) {
return;
}
item.getProperty().eAdapters().remove(dirtyListener);
item = (FileItem) o;
item.getProperty().eAdapters().add(dirtyListener);
if (isEditable()) {
isEditable = true;
rEditorInput.getFile().setReadOnly(false);
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setFocus();
ISourceViewer viewer = getViewer();
if (viewer != null) {
StyledText styledText = viewer.getTextWidget();
if (styledText != null) {
styledText.setBackground(bgColorForEditabeItem);
styledText.setDragDetect(true);
}
}
}
});
try {
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
if (o instanceof RoutineItem) {
ITalendSynchronizer routineSynchronizer = service.createJavaRoutineSynchronizer();
routineSynchronizer.syncRoutine((RoutineItem) o, true);
} else if (o instanceof SQLPatternItem) {
ISQLPatternSynchronizer sqlPatternSynchronizer = service.getSQLPatternSynchronizer();
sqlPatternSynchronizer.syncSQLPattern((SQLPatternItem) o, true);
} else {
//$NON-NLS-1$
org.talend.commons.exception.ExceptionHandler.process(new Exception("Uncatched case"));
}
setName();
} catch (Exception e) {
org.talend.commons.exception.ExceptionHandler.process(e);
}
}
}
}
}
}
}, new Hashtable<String, String>(//$NON-NLS-1$
Collections.singletonMap(EventConstants.EVENT_TOPIC, Constant.REPOSITORY_ITEM_EVENT_PREFIX + "*")));
}
use of org.eclipse.swt.custom.StyledText in project tdi-studio-se by Talend.
the class DropContextAnalyzer method init.
/**
* DOC amaumont Comment method "init".
*/
private void init() {
DropTarget dropTarget = (DropTarget) event.widget;
Control controlTarget = dropTarget.getControl();
dataMapTableViewTarget = mapperManager.retrieveDataMapTableView(controlTarget);
if (controlTarget instanceof Table) {
currentTableTarget = (Table) dropTarget.getControl();
} else if (controlTarget instanceof StyledText) {
currentStyledTextTarget = (StyledText) dropTarget.getControl();
} else {
//$NON-NLS-1$
throw new IllegalArgumentException(Messages.getString("DropContextAnalyzer.0", controlTarget.toString()));
}
zoneTarget = dataMapTableViewTarget.getZone();
draggedData = TableEntriesTransfer.getInstance().getDraggedData();
dataMapTableViewSource = (DataMapTableView) draggedData.getDataMapTableViewSource();
tableItemSource = draggedData.getTableItemSource();
zoneSource = dataMapTableViewSource.getZone();
if (currentTableTarget != null) {
analyzeCursorOverExpressionCell();
}
invalidKeyPressed = hasInvalidKeyPressed();
isDropValid = checkDropIsValid();
analyzeForFeedback();
analyzeForDetail();
// System.out.println("isCursorOverExpressionCell="+isCursorOverExpressionCell);
}
use of org.eclipse.swt.custom.StyledText in project tdi-studio-se by Talend.
the class AbstractElementPropertySectionController method addDragAndDropTarget.
/**
* Accept Text and StyledText control.
*
* @param labelText
*/
public void addDragAndDropTarget(final Control textControl) {
DropTargetListener dropTargetListener = new DropTargetListener() {
String propertyName = null;
@Override
public void dragEnter(final DropTargetEvent event) {
}
@Override
public void dragLeave(final DropTargetEvent event) {
}
@Override
public void dragOperationChanged(final DropTargetEvent event) {
}
@Override
public void dragOver(final DropTargetEvent event) {
if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
propertyName = getParameterName(textControl);
for (int i = 0; i < elem.getElementParameters().size(); i++) {
IElementParameter param = elem.getElementParameters().get(i);
if (param.getName().equals(propertyName)) {
if (param.isReadOnly()) {
event.detail = DND.ERROR_INVALID_DATA;
}
}
}
}
}
@Override
public void drop(final DropTargetEvent event) {
if (propertyName != null) {
String text;
if (textControl instanceof StyledText) {
text = ((StyledText) textControl).getText() + (String) event.data;
((StyledText) textControl).setText(text);
} else {
text = ((Text) textControl).getText() + (String) event.data;
((Text) textControl).setText(text);
}
Command cmd = new PropertyChangeCommand(elem, propertyName, text);
// getCommandStack().execute(cmd);
executeCommand(cmd);
}
}
@Override
public void dropAccept(final DropTargetEvent event) {
}
};
DropTarget target = new DropTarget(textControl, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance() };
target.setTransfer(transfers);
target.addDropListener(dropTargetListener);
}
use of org.eclipse.swt.custom.StyledText in project tdi-studio-se by Talend.
the class ContextParameterExtractor method buildParameterFrom.
private static IContextParameter buildParameterFrom(final Control text, final IContextManager manager, final String parameterName) {
//$NON-NLS-1$
String nameProposal = "";
if (text instanceof Text) {
nameProposal = ((Text) text).getSelectionText();
if (nameProposal.length() == 0) {
nameProposal = ((Text) text).getText();
}
} else {
if (text instanceof StyledText) {
nameProposal = ((StyledText) text).getSelectionText();
if (nameProposal.length() == 0) {
nameProposal = ((StyledText) text).getText();
}
}
}
if (LanguageManager.getCurrentLanguage().equals(ECodeLanguage.JAVA)) {
nameProposal = TalendTextUtils.removeQuotes(nameProposal);
}
String value = nameProposal;
if (ContextParameterUtils.containContextVariables(value)) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
new Shell(), //$NON-NLS-1$
Messages.getString("ContextParameterExtractor.ExistedTitle"), //$NON-NLS-1$
Messages.getString("ContextParameterExtractor.ExistedMessages"));
return null;
}
//$NON-NLS-1$ //$NON-NLS-2$
nameProposal = nameProposal.replace(" ", "_");
IContextParameter parameter = new JobContextParameter();
if (manager.checkValidParameterName(null, parameterName)) {
parameter.setName(parameterName);
} else if (manager.checkValidParameterName(null, nameProposal)) {
parameter.setName(nameProposal);
} else {
//$NON-NLS-1$
parameter.setName("");
}
ECodeLanguage curLanguage = LanguageManager.getCurrentLanguage();
if (curLanguage == ECodeLanguage.PERL) {
parameter.setType(MetadataTalendType.getDefaultTalendType());
} else {
parameter.setType(JavaTypesManager.getDefaultJavaType().getId());
}
//$NON-NLS-1$
parameter.setPrompt(parameterName + "?");
//$NON-NLS-1$
parameter.setComment("");
parameter.setValue(value);
return parameter;
}
use of org.eclipse.swt.custom.StyledText in project tdi-studio-se by Talend.
the class UIManager method getTableEntryPosition.
/**
* DOC amaumont Comment method "getTableEntryPosition".
*
* @param manager TODO
* @param tableEntry
* @param forceRecalculate TODO
* @return
*/
public Point getTableEntryPosition(ITableEntry tableEntry, boolean forceRecalculate) {
DataMapTableView dataMapTableView = mapperManager.retrieveDataMapTableView(tableEntry);
int entriesSize = 0;
int minHeight = dataMapTableView.getTableViewerCreatorForColumns().getTable().getHeaderHeight() + dataMapTableView.getTableViewerCreatorForColumns().getTable().getItemHeight();
TableItem[] tableItems = new TableItem[0];
if (tableEntry instanceof InputColumnTableEntry || tableEntry instanceof OutputColumnTableEntry) {
tableItems = dataMapTableView.getTableViewerCreatorForColumns().getTable().getItems();
AbstractInOutTable abstractInOutTable = (AbstractInOutTable) dataMapTableView.getDataMapTable();
if (dataMapTableView.getZone() == Zone.OUTPUTS) {
OutputTable outputTable = (OutputTable) abstractInOutTable;
List<IColumnEntry> oldOuputEntries = outputTable.getDataMapTableEntries();
entriesSize = oldOuputEntries.size();
}
if (dataMapTableView.getZone() == Zone.INPUTS) {
InputTable inputTable = (InputTable) abstractInOutTable;
List<IColumnEntry> oldOuputEntries = inputTable.getDataMapTableEntries();
entriesSize = oldOuputEntries.size();
}
}
Rectangle tableViewBounds = dataMapTableView.getBounds();
Point pointFromTableViewOrigin = null;
Display display = dataMapTableView.getDisplay();
Point returnedPoint = new Point(0, 0);
TableEntryProperties tableEntryProperties = null;
int itemIndex = 0;
if (tableEntry instanceof IColumnEntry || tableEntry instanceof FilterTableEntry || tableEntry instanceof GlobalMapEntry) {
tableEntryProperties = mapperManager.getTableEntryProperties(tableEntry);
returnedPoint = tableEntryProperties.position;
if (forceRecalculate || returnedPoint == null) {
int y;
TableItem tableItem = mapperManager.retrieveTableItem(tableEntry);
boolean isOutputEntry = tableEntry instanceof OutputColumnTableEntry;
boolean isIntputEntry = tableEntry instanceof InputColumnTableEntry;
boolean checked = false;
for (int i = 0; i < tableItems.length; i++) {
if (tableItems[i].getData() == tableEntry) {
itemIndex = i;
break;
}
}
boolean allIsNull = false;
if (tableItem == null && (isIntputEntry || isOutputEntry)) {
if (tableItems.length > 0) {
tableItem = tableItems[0];
checked = true;
} else {
allIsNull = true;
}
}
if (!allIsNull) {
Table table = tableItem.getParent();
// FIX for issue 1225 ("1" parameter added)
Rectangle boundsTableItem = tableItem.getBounds(1);
y = boundsTableItem.y + table.getItemHeight() / 2 + dataMapTableView.getBorderWidth();
if (isOutputEntry || isIntputEntry) {
if (entriesSize != tableItems.length) {
y = boundsTableItem.y + table.getItemHeight() / 2 + dataMapTableView.getBorderWidth();
}
}
if (checked) {
y = boundsTableItem.y + dataMapTableView.getBorderWidth();
checked = false;
}
int x = 0;
if (y < 0) {
y = 0;
}
Point point = new Point(x, y);
pointFromTableViewOrigin = display.map(tableItem.getParent(), dataMapTableView, point);
} else {
Text columnFilterText = dataMapTableView.getColumnNameFilterText();
Point point = new Point(-dataMapTableView.getBorderWidth() - 19, minHeight);
pointFromTableViewOrigin = display.map(columnFilterText, dataMapTableView, point);
}
}
} else if (tableEntry instanceof ExpressionFilterEntry) {
StyledText expressionFilterText = dataMapTableView.getExpressionFilterText();
// dataMapTableView.getex
Point point = new Point(-dataMapTableView.getBorderWidth() - 19, 16);
pointFromTableViewOrigin = display.map(expressionFilterText, dataMapTableView, point);
} else {
//$NON-NLS-1$
throw new IllegalStateException("Case not found");
}
if (pointFromTableViewOrigin.y > tableViewBounds.height - TableEntriesManager.HEIGHT_REACTION) {
pointFromTableViewOrigin.y = tableViewBounds.height - TableEntriesManager.HEIGHT_REACTION;
}
returnedPoint = convertPointToReferenceOrigin(getReferenceComposite(), pointFromTableViewOrigin, dataMapTableView);
if (tableEntryProperties != null) {
tableEntryProperties.position = returnedPoint;
}
return returnedPoint;
}
Aggregations