Search in sources :

Example 26 with StyledText

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 + "*")));
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) StyledText(org.eclipse.swt.custom.StyledText) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) EventHandler(org.osgi.service.event.EventHandler) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) FileItem(org.talend.core.model.properties.FileItem) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) ResourceChangeEvent(org.eclipse.core.internal.events.ResourceChangeEvent) Event(org.osgi.service.event.Event) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Property(org.talend.core.model.properties.Property)

Example 27 with StyledText

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);
}
Also used : Control(org.eclipse.swt.widgets.Control) IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) Table(org.eclipse.swt.widgets.Table) InputTable(org.talend.designer.mapper.model.table.InputTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) StyledText(org.eclipse.swt.custom.StyledText) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 28 with StyledText

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);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) Command(org.eclipse.gef.commands.Command) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) IElementParameter(org.talend.core.model.process.IElementParameter) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) ReconcilerStyledText(org.talend.designer.core.ui.viewer.ReconcilerStyledText) DropTarget(org.eclipse.swt.dnd.DropTarget)

Example 29 with StyledText

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;
}
Also used : JobContextParameter(org.talend.core.model.context.JobContextParameter) Shell(org.eclipse.swt.widgets.Shell) StyledText(org.eclipse.swt.custom.StyledText) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) IContextParameter(org.talend.core.model.process.IContextParameter) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 30 with StyledText

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;
}
Also used : IDataMapTable(org.talend.designer.abstractmap.model.table.IDataMapTable) InputTable(org.talend.designer.mapper.model.table.InputTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) OutputTable(org.talend.designer.mapper.model.table.OutputTable) ExternalMapperTable(org.talend.designer.mapper.external.data.ExternalMapperTable) Table(org.eclipse.swt.widgets.Table) AbstractDataMapTable(org.talend.designer.mapper.model.table.AbstractDataMapTable) StyledText(org.eclipse.swt.custom.StyledText) TableItem(org.eclipse.swt.widgets.TableItem) AbstractInOutTable(org.talend.designer.mapper.model.table.AbstractInOutTable) Rectangle(org.eclipse.swt.graphics.Rectangle) FilterTableEntry(org.talend.designer.mapper.model.tableentry.FilterTableEntry) InputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.InputDataMapTableView) OutputDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.OutputDataMapTableView) VarsDataMapTableView(org.talend.designer.mapper.ui.visualmap.table.VarsDataMapTableView) DataMapTableView(org.talend.designer.mapper.ui.visualmap.table.DataMapTableView) OutputColumnTableEntry(org.talend.designer.mapper.model.tableentry.OutputColumnTableEntry) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) IColumnEntry(org.talend.designer.abstractmap.model.tableentry.IColumnEntry) TableEntryProperties(org.talend.designer.mapper.ui.visualmap.TableEntryProperties) Point(org.eclipse.swt.graphics.Point) OutputTable(org.talend.designer.mapper.model.table.OutputTable) InputTable(org.talend.designer.mapper.model.table.InputTable) InputColumnTableEntry(org.talend.designer.mapper.model.tableentry.InputColumnTableEntry) GlobalMapEntry(org.talend.designer.mapper.model.tableentry.GlobalMapEntry) ExpressionFilterEntry(org.talend.designer.mapper.model.tableentry.ExpressionFilterEntry) Display(org.eclipse.swt.widgets.Display)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)157 GridData (org.eclipse.swt.layout.GridData)52 Composite (org.eclipse.swt.widgets.Composite)50 GridLayout (org.eclipse.swt.layout.GridLayout)41 Point (org.eclipse.swt.graphics.Point)37 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)22 Control (org.eclipse.swt.widgets.Control)22 Label (org.eclipse.swt.widgets.Label)17 FillLayout (org.eclipse.swt.layout.FillLayout)13 CTabItem (org.eclipse.swt.custom.CTabItem)12 SashForm (org.eclipse.swt.custom.SashForm)12 Button (org.eclipse.swt.widgets.Button)12 ModifyEvent (org.eclipse.swt.events.ModifyEvent)10 ModifyListener (org.eclipse.swt.events.ModifyListener)10 TextTransfer (org.eclipse.swt.dnd.TextTransfer)8 Listener (org.eclipse.swt.widgets.Listener)8 UnnotifiableColorStyledText (org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText)8 Clipboard (org.eclipse.swt.dnd.Clipboard)7 DisposeEvent (org.eclipse.swt.events.DisposeEvent)7