Search in sources :

Example 6 with WSWhereCondition

use of com.amalto.workbench.webservices.WSWhereCondition in project tmdm-studio-se by Talend.

the class ViewBrowserMainPage method createCharacteristicsContent.

@Override
protected void createCharacteristicsContent(FormToolkit toolkit, Composite charComposite) {
    try {
        Label vbeLabel = toolkit.createLabel(charComposite, Messages.ViewBrowserMainPage_ViewableElements, SWT.NULL);
        vbeLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
        Label sbeLabel = toolkit.createLabel(charComposite, Messages.ViewBrowserMainPage_SearchableElements, SWT.NULL);
        sbeLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
        viewableBEsList = new List(charComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
        viewableBEsList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) viewableBEsList.getLayoutData()).heightHint = 100;
        searchableBEsList = new List(charComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
        searchableBEsList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
        ((GridData) searchableBEsList.getLayoutData()).heightHint = 100;
        Label wcLabel = toolkit.createLabel(charComposite, Messages.ViewBrowserMainPage_Conditions, SWT.NULL);
        wcLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 2, 1));
        wcListViewer = new ListViewer(charComposite, SWT.BORDER);
        wcListViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
        ((GridData) wcListViewer.getControl().getLayoutData()).minimumHeight = 100;
        wcListViewer.setContentProvider(new IStructuredContentProvider() {

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }

            public Object[] getElements(Object inputElement) {
                return ((WSView) inputElement).getWhereConditions().toArray();
            }
        });
        wcListViewer.setLabelProvider(new ILabelProvider() {

            public Image getImage(Object element) {
                return null;
            }

            public String getText(Object element) {
                WSWhereCondition wc = (WSWhereCondition) element;
                // $NON-NLS-1$
                String text = wc.getLeftPath() + " ";
                if (wc.getOperator().equals(WSWhereOperator.CONTAINS)) {
                    // $NON-NLS-1$
                    text += "Contains";
                } else if (wc.getOperator().equals(WSWhereOperator.CONTAINS_SENTENCE)) {
                    // $NON-NLS-1$
                    text += "contains the sentence";
                } else if (wc.getOperator().equals(WSWhereOperator.EQUALS)) {
                    // $NON-NLS-1$
                    text += "=";
                } else if (wc.getOperator().equals(WSWhereOperator.GREATER_THAN)) {
                    // $NON-NLS-1$
                    text += ">";
                } else if (wc.getOperator().equals(WSWhereOperator.GREATER_THAN_OR_EQUAL)) {
                    // $NON-NLS-1$
                    text += ">=";
                } else if (wc.getOperator().equals(WSWhereOperator.JOIN)) {
                    // $NON-NLS-1$
                    text += "Joins With";
                } else if (wc.getOperator().equals(WSWhereOperator.LOWER_THAN)) {
                    // $NON-NLS-1$
                    text += "<";
                } else if (wc.getOperator().equals(WSWhereOperator.LOWER_THAN_OR_EQUAL)) {
                    // $NON-NLS-1$
                    text += "<=";
                } else if (wc.getOperator().equals(WSWhereOperator.NOT_EQUALS)) {
                    // $NON-NLS-1$
                    text += "!=";
                } else if (wc.getOperator().equals(WSWhereOperator.STARTSWITH)) {
                    // $NON-NLS-1$
                    text += "Starts With";
                } else if (wc.getOperator().equals(WSWhereOperator.EMPTY_NULL)) {
                    // $NON-NLS-1$
                    text += "Is Empty Or Null";
                } else if (wc.getOperator().equals(WSWhereOperator.FULLTEXTSEARCH)) {
                    // $NON-NLS-1$
                    text += "whole content contains";
                }
                // $NON-NLS-1$
                text += " ";
                if (!wc.getOperator().equals(WSWhereOperator.JOIN)) {
                    // $NON-NLS-1$
                    text += "\"";
                }
                text += wc.getRightValueOrPath();
                if (!wc.getOperator().equals(WSWhereOperator.JOIN)) {
                    // $NON-NLS-1$
                    text += "\"";
                }
                // $NON-NLS-1$
                text += " ";
                if (wc.getStringPredicate().equals(WSStringPredicate.AND)) {
                    // $NON-NLS-1$
                    text += "[and]";
                } else if (wc.getStringPredicate().equals(WSStringPredicate.NONE)) {
                    // $NON-NLS-1$
                    text += "";
                } else if (wc.getStringPredicate().equals(WSStringPredicate.OR)) {
                    // $NON-NLS-1$
                    text += "[or]";
                } else if (wc.getStringPredicate().equals(WSStringPredicate.NOT)) {
                    // $NON-NLS-1$
                    text += "[not]";
                }
                return text;
            }

            public void addListener(ILabelProviderListener listener) {
            }

            public void dispose() {
            }

            public boolean isLabelProperty(Object element, String property) {
                return false;
            }

            public void removeListener(ILabelProviderListener listener) {
            }
        });
        int columns = 6;
        Composite resultsGroup = this.getNewSectionComposite(Messages.ViewBrowserMainPage_SearchAndResults);
        resultsGroup.setLayout(new GridLayout(columns, false));
        Composite createComposite = toolkit.createComposite(resultsGroup);
        GridLayout layout = new GridLayout(3, false);
        layout.marginWidth = 0;
        createComposite.setLayout(layout);
        createComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
        Label containerLabel = toolkit.createLabel(createComposite, Messages.ViewBrowserMainPage_Container, SWT.NULL);
        containerLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
        dataClusterCombo = new Combo(createComposite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
        dataClusterCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
        ((GridData) dataClusterCombo.getLayoutData()).minimumWidth = 100;
        clusterTypeCombo = new Combo(createComposite, SWT.READ_ONLY | SWT.SINGLE);
        GridData typeLayout = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
        typeLayout.horizontalIndent = 10;
        clusterTypeCombo.setLayoutData(typeLayout);
        Label searchOnLabel = toolkit.createLabel(resultsGroup, Messages.ViewBrowserMainPage_SearchOn, SWT.NULL);
        GridData layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
        layoutData.horizontalIndent = 20;
        searchOnLabel.setLayoutData(layoutData);
        searchItemCombo = new Combo(resultsGroup, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
        searchItemCombo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1));
        ((GridData) searchItemCombo.getLayoutData()).minimumWidth = 100;
        searchItemCombo.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (FULL_TEXT.equals(searchItemCombo.getText())) {
                    matchAllWordsBtn.setEnabled(true);
                } else {
                    matchAllWordsBtn.setSelection(false);
                    matchAllWordsBtn.setEnabled(false);
                }
            }
        });
        // $NON-NLS-1$
        searchText = toolkit.createText(resultsGroup, "", SWT.BORDER);
        searchText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        searchText.addKeyListener(new KeyListener() {

            public void keyPressed(KeyEvent e) {
            }

            public void keyReleased(KeyEvent e) {
                if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                    ViewBrowserMainPage.this.resultsViewer.setInput(getResults());
                }
            }
        });
        Button bSearch = toolkit.createButton(resultsGroup, Messages.ViewBrowserMainPage_Search, SWT.CENTER);
        bSearch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
        bSearch.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event event) {
                ViewBrowserMainPage.this.resultsViewer.setInput(getResults());
            }
        });
        matchAllWordsBtn = toolkit.createButton(resultsGroup, Messages.ViewBrowserMainPage_MatchWholeSentence, SWT.CHECK);
        matchAllWordsBtn.setSelection(true);
        // $NON-NLS-1$
        resultsLabel = toolkit.createLabel(resultsGroup, "", SWT.NULL);
        GridData resultLayoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false, columns - 1, 1);
        resultLayoutData.widthHint = 100;
        resultsLabel.setLayoutData(resultLayoutData);
        resultsViewer = new TableViewer(resultsGroup);
        resultsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
        ((GridData) resultsViewer.getControl().getLayoutData()).heightHint = 500;
        resultsViewer.setContentProvider(new ArrayContentProvider());
        resultsViewer.setLabelProvider(new XMLTableLabelProvider());
        resultsViewer.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                resultsViewer.setSelection(event.getSelection());
                try {
                    new DOMViewAction(ViewBrowserMainPage.this.getSite().getShell(), resultsViewer).run();
                } catch (Exception e) {
                    MessageDialog.openError(ViewBrowserMainPage.this.getSite().getShell(), Messages._Error, Messages.bind(Messages.ViewBrowserMainPage_ErrorMsg, e.getClass().getName(), e.getLocalizedMessage()));
                }
            }
        });
        hookContextMenu();
        addListener();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
Also used : IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IXObjectModelListener(com.amalto.workbench.models.IXObjectModelListener) IMenuListener(org.eclipse.jface.action.IMenuListener) Listener(org.eclipse.swt.widgets.Listener) KeyListener(org.eclipse.swt.events.KeyListener) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) Viewer(org.eclipse.jface.viewers.Viewer) Combo(org.eclipse.swt.widgets.Combo) Image(org.eclipse.swt.graphics.Image) WSView(com.amalto.workbench.webservices.WSView) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) ArrayList(java.util.ArrayList) ListViewer(org.eclipse.jface.viewers.ListViewer) WSWhereCondition(com.amalto.workbench.webservices.WSWhereCondition) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) XtentisException(com.amalto.workbench.utils.XtentisException) MalformedURLException(java.net.MalformedURLException) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) KeyEvent(org.eclipse.swt.events.KeyEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TreeObject(com.amalto.workbench.models.TreeObject) KeyListener(org.eclipse.swt.events.KeyListener) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 7 with WSWhereCondition

use of com.amalto.workbench.webservices.WSWhereCondition in project tmdm-studio-se by Talend.

the class ViewBrowserMainPage method getResults.

public String[] getResults() {
    Cursor waitCursor = null;
    try {
        Display display = getEditor().getSite().getPage().getWorkbenchWindow().getWorkbench().getDisplay();
        waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
        this.getSite().getShell().setCursor(waitCursor);
        TMDMService service = getMDMService();
        java.util.List<String> results = null;
        int maxItem = 10;
        // $NON-NLS-1$ //$NON-NLS-2$
        String search = "".equals(searchText.getText()) ? "*" : searchText.getText();
        WSDataClusterPK wsDataClusterPK = new WSDataClusterPK(dataClusterCombo.getText() + getPkAddition());
        if (FULL_TEXT.equals(searchItemCombo.getText())) {
            boolean matchAllWords = matchAllWordsBtn.getSelection();
            results = service.quickSearch(new WSQuickSearch(null, matchAllWords, maxItem, null, search, 0, Integer.MAX_VALUE, wsDataClusterPK, getViewPK())).getStrings();
        } else {
            WSView wsview = (WSView) wcListViewer.getInput();
            java.util.List<WSWhereCondition> array = wsview.getWhereConditions();
            java.util.List<WSWhereItem> conditions = new ArrayList<WSWhereItem>();
            for (WSWhereCondition condition : array) {
                WSWhereItem item = new WSWhereItem(null, condition, null);
                conditions.add(item);
            }
            WSWhereCondition condition = new WSWhereCondition(searchItemCombo.getText(), WSWhereOperator.CONTAINS, search, true, WSStringPredicate.AND);
            WSWhereItem item = new WSWhereItem(null, condition, null);
            conditions.add(item);
            WSWhereAnd and = new WSWhereAnd(conditions);
            WSWhereItem wi = new WSWhereItem(and, null, null);
            results = service.viewSearch(new WSViewSearch("ascending", maxItem, null, 0, -1, wi, wsDataClusterPK, getViewPK())).getStrings();
        }
        resultsLabel.setText(Messages.bind(Messages.ViewBrowserMainPage_Results, results.size() - 1));
        if (results.size() > 1) {
            return results.subList(1, results.size()).toArray(new String[0]);
        }
        return new String[0];
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if ((e.getLocalizedMessage() != null) && e.getLocalizedMessage().contains("10000")) {
            MessageDialog.openError(this.getSite().getShell(), Messages.ViewBrowserMainPage_ErrorTitle4, Messages.ViewBrowserMainPage_ErrorMsg4);
        } else if (!Util.handleConnectionException(this.getSite().getShell(), e, Messages.ViewBrowserMainPage_ErrorTitle5)) {
            MessageDialog.openError(this.getSite().getShell(), Messages.ViewBrowserMainPage_ErrorTitle5, e.getLocalizedMessage());
        }
        return null;
    } finally {
        try {
            this.getSite().getShell().setCursor(null);
            waitCursor.dispose();
        } catch (Exception e) {
        }
    }
}
Also used : WSWhereCondition(com.amalto.workbench.webservices.WSWhereCondition) ArrayList(java.util.ArrayList) WSWhereItem(com.amalto.workbench.webservices.WSWhereItem) Cursor(org.eclipse.swt.graphics.Cursor) WSView(com.amalto.workbench.webservices.WSView) WSWhereAnd(com.amalto.workbench.webservices.WSWhereAnd) XtentisException(com.amalto.workbench.utils.XtentisException) MalformedURLException(java.net.MalformedURLException) WSDataClusterPK(com.amalto.workbench.webservices.WSDataClusterPK) WSQuickSearch(com.amalto.workbench.webservices.WSQuickSearch) TMDMService(com.amalto.workbench.webservices.TMDMService) WSViewSearch(com.amalto.workbench.webservices.WSViewSearch) Display(org.eclipse.swt.widgets.Display)

Aggregations

WSWhereCondition (com.amalto.workbench.webservices.WSWhereCondition)7 XtentisException (com.amalto.workbench.utils.XtentisException)4 WSView (com.amalto.workbench.webservices.WSView)4 ArrayList (java.util.ArrayList)4 Line (com.amalto.workbench.models.Line)2 WSBoolean (com.amalto.workbench.webservices.WSBoolean)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 List (org.eclipse.swt.widgets.List)2 Test (org.junit.Test)2 IXObjectModelListener (com.amalto.workbench.models.IXObjectModelListener)1 TreeObject (com.amalto.workbench.models.TreeObject)1 TMDMService (com.amalto.workbench.webservices.TMDMService)1 WSDataClusterPK (com.amalto.workbench.webservices.WSDataClusterPK)1 WSQuickSearch (com.amalto.workbench.webservices.WSQuickSearch)1 WSStringPredicate (com.amalto.workbench.webservices.WSStringPredicate)1 WSViewSearch (com.amalto.workbench.webservices.WSViewSearch)1 WSWhereAnd (com.amalto.workbench.webservices.WSWhereAnd)1 WSWhereItem (com.amalto.workbench.webservices.WSWhereItem)1 WSWhereOperator (com.amalto.workbench.webservices.WSWhereOperator)1