Search in sources :

Example 66 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project tmdm-studio-se by Talend.

the class StoredProcedureMainPage method createCharacteristicsContent.

@Override
protected void createCharacteristicsContent(FormToolkit toolkit, Composite charComposite) {
    try {
        WSStoredProcedure wsStoredProcedure = (WSStoredProcedure) (getXObject().getWsObject());
        // description
        Label descriptionLabel = toolkit.createLabel(charComposite, Messages.StoredProcedureMainPage_4, SWT.NULL);
        descriptionLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 1, 1));
        // $NON-NLS-1$
        descriptionText = toolkit.createText(charComposite, "", SWT.BORDER);
        descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        // $NON-NLS-1$
        descriptionText.setText(wsStoredProcedure.getDescription() == null ? "" : wsStoredProcedure.getDescription());
        descriptionText.addModifyListener(this);
        // Procedure
        Group storedProcedureGroup = new Group(charComposite, SWT.SHADOW_NONE);
        storedProcedureGroup.setText(Messages.StoredProcedureMainPage_5);
        storedProcedureGroup.setLayout(new GridLayout(1, true));
        storedProcedureGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        ((GridData) storedProcedureGroup.getLayoutData()).minimumHeight = 100;
        procedureViewer = new SourceViewer(storedProcedureGroup, new VerticalRuler(10), SWT.V_SCROLL);
        procedureViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        procedureViewer.addTextListener(this);
        WidgetUtils.initRedoUndo(procedureViewer);
        refreshCacheBtn = toolkit.createButton(charComposite, Messages.StoredProcedureMainPage_6, SWT.CHECK);
        refreshCacheBtn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        refreshCacheBtn.addSelectionListener(new SelectionListener() {

            public void widgetSelected(SelectionEvent e) {
                markDirty();
            }

            public void widgetDefaultSelected(SelectionEvent e) {
                markDirty();
            }
        });
        /**
         **********************************************************
         * Execute Stored Procedure
         ***********************************************************
         */
        createCompDropTarget();
        Composite resultsGroup = this.getNewSectionComposite(Messages.StoredProcedureMainPage_7);
        resultsGroup.setLayout(new GridLayout(4, false));
        // data cluster
        Hyperlink dataClusterLink = toolkit.createHyperlink(resultsGroup, Messages.StoredProcedureMainPage_8, SWT.NULL);
        dataClusterLink.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
        dataClusterLink.addHyperlinkListener(new IHyperlinkListener() {

            public void linkEntered(org.eclipse.ui.forms.events.HyperlinkEvent e) {
            }

            public void linkExited(org.eclipse.ui.forms.events.HyperlinkEvent e) {
            }

            public void linkActivated(org.eclipse.ui.forms.events.HyperlinkEvent e) {
                if (!isLocalInput()) {
                    TreeParent serverRoot = StoredProcedureMainPage.this.getXObject().getServerRoot();
                    TreeObject iaObject = new TreeObject(StoredProcedureMainPage.this.dataClusterCombo.getText(), serverRoot, TreeObject.DATA_CLUSTER, new WSDataClusterPK(StoredProcedureMainPage.this.dataClusterCombo.getText()), null);
                    (new EditXObjectAction(iaObject, StoredProcedureMainPage.this.getSite().getPage())).run();
                }
            }
        });
        dataClusterCombo = new Combo(resultsGroup, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
        dataClusterCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
        Button executeButton = new Button(resultsGroup, SWT.PUSH);
        executeButton.setText(Messages.StoredProcedureMainPage_9);
        executeButton.addMouseListener(new MouseListener() {

            public void mouseUp(MouseEvent e) {
                executeProcedure();
            }

            public void mouseDoubleClick(MouseEvent e) {
            }

            public void mouseDown(MouseEvent e) {
            }
        });
        resultsLabel = toolkit.createLabel(resultsGroup, // $NON-NLS-1$
        "                                                                                                           ", SWT.NULL);
        resultsLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 1, 1));
        resultsViewer = new TableViewer(resultsGroup);
        resultsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 4, 1));
        ((GridData) resultsViewer.getControl().getLayoutData()).heightHint = 300;
        resultsViewer.setContentProvider(new ArrayContentProvider());
        resultsViewer.setLabelProvider(new XMLTableLabelProvider());
        resultsViewer.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                resultsViewer.setSelection(event.getSelection());
                new ResultsViewAction(StoredProcedureMainPage.this.getSite().getShell(), resultsViewer).run();
            }
        });
        hookContextMenu();
        refreshData();
        dataClusterCombo.select(0);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) SourceViewer(org.eclipse.jface.text.source.SourceViewer) TreeParent(com.amalto.workbench.models.TreeParent) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) MouseListener(org.eclipse.swt.events.MouseListener) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IHyperlinkListener(org.eclipse.ui.forms.events.IHyperlinkListener) WSStoredProcedure(com.amalto.workbench.webservices.WSStoredProcedure) VerticalRuler(org.eclipse.jface.text.source.VerticalRuler) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) EditXObjectAction(com.amalto.workbench.actions.EditXObjectAction) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TreeObject(com.amalto.workbench.models.TreeObject) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink)

Example 67 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project tmdm-studio-se by Talend.

the class SchematronExpressBuilder method create.

private void create() {
    com = new Composite(parent, SWT.NONE);
    com.setLayout(getLayout(3));
    // expression
    Group expressG = new Group(com, SWT.NONE);
    expressG.setText(Messages.SchematronExpressBuilder_Expression);
    expressG.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 2));
    expressG.setLayout(getLayout(1));
    // top button group
    Composite topCom = new Composite(expressG, 0);
    Button clearBtn = new Button(topCom, SWT.PUSH);
    topCom.setLayout(getLayout(4));
    clearBtn.setText(Messages.SchematronExpressBuilder_Clear);
    clearBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, false, false, 1, 1));
    clearBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            // $NON-NLS-1$
            sourceViewer.setDocument(new Document(""));
        }
    });
    org.eclipse.jface.text.Document doc = new org.eclipse.jface.text.Document(value);
    sourceViewer = new SourceViewer(expressG, new VerticalRuler(5), SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 6);
    gd.heightHint = 150;
    sourceViewer.getControl().setLayoutData(gd);
    WidgetUtils.initRedoUndo(sourceViewer);
    sourceViewer.setDocument(doc);
    // bottom button group
    Composite bottomCom = new Composite(expressG, 0);
    GridLayout ly = getLayout(4);
    bottomCom.setLayout(ly);
    Composite com1 = new Composite(bottomCom, 0);
    com1.setLayout(getLayout(4));
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
    String[] strs1 = { "+", "-", "*", "div" };
    for (String str : strs1) {
        final Button btn = new Button(com1, SWT.PUSH);
        btn.setText(str);
        btn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // getTextWidget().setText(getText() + btn.getText());
                insertText(btn.getText());
            }
        });
    }
    Composite com2 = new Composite(bottomCom, 0);
    com2.setLayout(getLayout(4));
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
    String[] strs2 = { "=", "!=", ">", "<" };
    for (String str : strs2) {
        final Button btn = new Button(com2, SWT.PUSH);
        btn.setText(str);
        btn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // getTextWidget().setText(getText() + btn.getText());
                insertText(btn.getText());
            }
        });
    }
    Composite com3 = new Composite(bottomCom, 0);
    com3.setLayout(getLayout(4));
    // $NON-NLS-1$//$NON-NLS-2$
    String[] strs3 = { "and", "or" };
    for (int i = 0; i < strs3.length; i++) {
        final Button btn = new Button(com3, SWT.PUSH);
        btn.setText(strs3[i]);
        btn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // getTextWidget().setText(getText() + btn.getText());
                insertText(btn.getText());
            }
        });
    }
    Composite com4 = new Composite(bottomCom, 0);
    com4.setLayout(getLayout(3));
    // $NON-NLS-1$//$NON-NLS-2$
    String[] strs4 = { ")", "(" };
    for (int i = 0; i < strs4.length; i++) {
        final Button btn = new Button(com4, SWT.PUSH);
        btn.setText(strs4[i]);
        btn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                // getTextWidget().setText(getText() + btn.getText());
                insertText(btn.getText());
            }
        });
    }
    Button xpathButton = new Button(com4, SWT.PUSH);
    // $NON-NLS-1$
    xpathButton.setText("xpath");
    xpathButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            XpathSelectDialog dlg = getXPathSelectDialog();
            dlg.setConceptName(conceptName);
            // dlg.setContext(context);
            dlg.setBlockOnOpen(true);
            dlg.open();
            if (dlg.getReturnCode() == Window.OK) {
                if (getTextWidget().getSelectionText().length() > 0) {
                    // getTextWidget().setText(getText().replace(getTextWidget().getSelectionText(),
                    // dlg.getXpath()));
                    getTextWidget().replaceTextRange(getTextWidget().getSelectionRanges()[0], getTextWidget().getSelectionRanges()[1], dlg.getXpath());
                } else {
                    // getTextWidget().setText(getText()+dlg.getXpath());
                    insertText(dlg.getXpath());
                }
            }
        }
    });
    // //test
    // Group testG=new Group(com,SWT.NONE);
    // testG.setText("Test");
    // GridData gd2=new GridData(SWT.FILL,SWT.FILL,true,true,1,2);
    // gd2.widthHint=190;
    // testG.setLayoutData(gd2);
    // testG.setLayout(getLayout(2));
    // Button btnStartTest=new Button(testG,SWT.PUSH);
    // btnStartTest.setText("Start Test");
    // btnStartTest.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false,1,1));
    // 
    // Button btnCleartTest=new Button(testG,SWT.PUSH);
    // btnCleartTest.setText("Clear");
    // btnCleartTest.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false,1,1));
    // 
    // testResult=new StyledText(testG,SWT.V_SCROLL|SWT.BORDER);
    // testResult.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,2,3));
    // btnCleartTest.addSelectionListener(new SelectionAdapter(){
    // @Override
    // public void widgetSelected(SelectionEvent e) {
    // testResult.setText("");
    // }
    // });
    // categories
    Group categoryG = new Group(com, SWT.NONE);
    categoryG.setText(Messages.SchematronExpressBuilder_Categories);
    GridData gd1 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd1.heightHint = 200;
    gd1.widthHint = 140;
    categoryG.setLayoutData(gd1);
    categoryG.setLayout(getLayout(1));
    categoryList = new List(categoryG, SWT.BORDER | SWT.V_SCROLL);
    categoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    for (XPathFunc c : categories) {
        categoryList.add(c.getCategory());
    }
    categoryList.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            funcList.removeAll();
            String c = categoryList.getSelection()[0];
            for (XPathFunc func : categories) {
                if (func.getCategory().equals(c)) {
                    curfc = func;
                    for (KeyValue kv : func.getFuncs()) {
                        funcList.add(kv.key);
                    }
                    break;
                }
            }
            if (funcList.getItems().length > 0) {
                funcList.select(0);
                helpTxt.setText(curfc.getFuncs().get(0).value);
            }
        }
    });
    // funcations
    Group functionG = new Group(com, SWT.NONE);
    functionG.setText(Messages.SchematronExpressBuilder_Functions);
    functionG.setLayout(getLayout(1));
    GridData gd3 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd3.widthHint = 220;
    functionG.setLayoutData(gd3);
    funcList = new List(functionG, SWT.BORDER | SWT.V_SCROLL);
    funcList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    funcList.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            getTextWidget().setText(getText() + funcList.getItem(funcList.getSelectionIndex()));
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            String c = funcList.getSelection()[0];
            for (KeyValue kv : curfc.getFuncs()) {
                if (kv.key.equals(c)) {
                    helpTxt.setText(kv.value);
                    break;
                }
            }
        }
    });
    // help
    Group helpG = new Group(com, SWT.NONE);
    helpG.setText(Messages.SchematronExpressBuilder_Help);
    helpG.setLayout(getLayout(1));
    helpG.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    helpTxt = new StyledText(helpG, SWT.BORDER | SWT.WRAP);
    GridData gd4 = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd4.widthHint = 210;
    helpTxt.setLayoutData(gd4);
}
Also used : Group(org.eclipse.swt.widgets.Group) SourceViewer(org.eclipse.jface.text.source.SourceViewer) KeyValue(com.amalto.workbench.models.KeyValue) XpathSelectDialog(com.amalto.workbench.dialogs.XpathSelectDialog) Document(org.eclipse.jface.text.Document) Document(org.eclipse.jface.text.Document) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(org.eclipse.swt.widgets.List) VerticalRuler(org.eclipse.jface.text.source.VerticalRuler) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) XPathFunc(com.amalto.workbench.models.XPathFunc) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SourceViewer (org.eclipse.jface.text.source.SourceViewer)67 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)39 IDocument (org.eclipse.jface.text.IDocument)26 GridData (org.eclipse.swt.layout.GridData)24 Label (org.eclipse.swt.widgets.Label)23 Composite (org.eclipse.swt.widgets.Composite)16 Document (org.eclipse.jface.text.Document)15 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)14 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)14 Control (org.eclipse.swt.widgets.Control)13 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Button (org.eclipse.swt.widgets.Button)11 Iterator (java.util.Iterator)10 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)8 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8