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);
}
}
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) {
}
}
}
Aggregations