[126844] first cut at adding support for filtering. added property pages for default filters on connection profile. refactored base connection profile property pages.
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/plugin.xml b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/plugin.xml
index d60203f..1bfb7db 100644
--- a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/plugin.xml
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/plugin.xml
@@ -16,13 +16,15 @@
<requires>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.core.runtime"/>
+ <import plugin="org.eclipse.core.resources"/>
+ <import plugin="com.ibm.icu"/>
<import plugin="org.eclipse.emf.ecore"/>
<import plugin="org.eclipse.emf.ecore.xmi"/>
<import plugin="org.eclipse.datatools.modelbase.sql"/>
- <import plugin="org.eclipse.datatools.connectivity.sqm.core"/>
<import plugin="org.eclipse.datatools.modelbase.dbdefinition"/>
- <import plugin="org.eclipse.core.resources"/>
- <import plugin="com.ibm.icu"/>
+ <import plugin="org.eclipse.datatools.connectivity.sqm.core"/>
+ <import plugin="org.eclipse.datatools.connectivity.ui"/>
+ <import plugin="org.eclipse.datatools.connectivity"/>
</requires>
<extension-point id="labelService" name="labelService" schema="schema/labelService.exsd"/>
@@ -301,4 +303,28 @@
displayType = "%cachedConnection">
</contributor>
</extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ class="org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter.SchemaFilterPropertyPage"
+ id="org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter.SchemaFilterPropertyPage"
+ name="Schema Filter"
+ objectClass="org.eclipse.datatools.connectivity.IConnectionProfile"/>
+ </extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ class="org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter.DefaultTableFilterPropertyPage"
+ id="org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter.DefaultTableFilterPropertyPage"
+ name="Default Table Filter"
+ objectClass="org.eclipse.datatools.connectivity.IConnectionProfile"/>
+ </extension>
+ <extension
+ point="org.eclipse.ui.propertyPages">
+ <page
+ class="org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter.DefaultSPFilterPropertyPage"
+ id="org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter.DefaultSPFilterPropertyPage"
+ name="Default Stored Procedure Filter"
+ objectClass="org.eclipse.datatools.connectivity.IConnectionProfile"/>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/ConnectionFilterPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/ConnectionFilterPropertyPage.java
new file mode 100644
index 0000000..72790eb
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/ConnectionFilterPropertyPage.java
@@ -0,0 +1,702 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Vector;
+
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.virtual.ISchemaNode;
+import org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.virtual.IVirtualNode;
+import org.eclipse.datatools.connectivity.sqm.core.internal.ui.util.resources.ResourceLoader;
+import org.eclipse.datatools.connectivity.sqm.internal.core.RDBCorePlugin;
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilter;
+import org.eclipse.datatools.connectivity.sqm.internal.core.containment.ContainmentService;
+import org.eclipse.datatools.modelbase.sql.schema.SQLObject;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+/**
+ * @author ledunnel
+ */
+public abstract class ConnectionFilterPropertyPage extends PropertyPage
+ implements Listener {
+
+ private static final ResourceLoader resource = ResourceLoader
+ .getResourceLoader();
+
+ protected ISelection selection;
+
+ private Button disableFilterCheckbox;
+
+ private Button expressionRadioButton;
+
+ private Button selectionRadioButton;
+
+ private Group expressionGroup;
+
+ private Group selectionGroup;
+
+ private Label expressionLabel;
+
+ private Combo expressionPredicate;
+
+ private Text expressionField;
+
+ private Combo selectionPredicate;
+
+ protected Table selectionTable;
+
+ private Button selectAllButton;
+
+ private Button deselectAllButton;
+
+ private String STARTS_WITH_TEXT;
+
+ private String CONTAINS_TEXT;
+
+ private String ENDS_WITH_TEXT;
+
+ private String NOT_START_WITH_TEXT;
+
+ private String NOT_CONTAIN_TEXT;
+
+ private String NOT_END_WITH_TEXT;
+
+ private String INCLUDE_ITEMS_TEXT;
+
+ private String EXCLUDE_ITEMS_TEXT;
+
+ private static String LIKE_PREDICATE_TEXT = "LIKE"; //$NON-NLS-1$
+
+ private static String IN_PREDICATE_TEXT = "IN"; //$NON-NLS-1$
+
+ private static String NOT_PREDICATE_TEXT = "NOT"; //$NON-NLS-1$
+
+ protected boolean isSelectionListPopulated = false;
+
+ private static String IDENTIFIER_DELIMITER = "'"; //$NON-NLS-1$
+
+ private String DEFAULT_MESSAGE = resource
+ .queryString("_UI_DESCRIPTION_FILTER"); //$NON-NLS-1$
+
+ private static final String SELECTION_ONLY_MESSAGE = resource
+ .queryString("_UI_DESCRIPTION_SELECTION_ONLY"); //$NON-NLS-1$
+
+ private boolean hideExpressionOption = false;
+
+ public ConnectionFilterPropertyPage() {
+ super();
+ setMessage(DEFAULT_MESSAGE);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
+ */
+ public void handleEvent(Event event) {
+ Widget source = event.widget;
+ if (source == disableFilterCheckbox) {
+ enableFilterSpecificationControls(!disableFilterCheckbox
+ .getSelection());
+ }
+ else if (source == expressionRadioButton) {
+ enableFilterSpecificationControls(true);
+ }
+ else if (source == selectAllButton) {
+ setAllTableItemsChecked(true);
+ }
+ else if (source == deselectAllButton) {
+ setAllTableItemsChecked(false);
+ }
+ setValid(validatePage());
+ }
+
+ private void setAllTableItemsChecked(boolean checked) {
+ TableItem[] tableItems = selectionTable.getItems();
+ int tableItemCount = tableItems.length;
+ for (int index = 0; index < tableItemCount; index++) {
+ tableItems[index].setChecked(checked);
+ }
+ }
+
+ private void enableExpressionGroupControls(boolean isEnabled) {
+ if (!hideExpressionOption) {
+ expressionGroup.setEnabled(isEnabled);
+ expressionLabel.setEnabled(isEnabled);
+ expressionPredicate.setEnabled(isEnabled);
+ expressionField.setEnabled(isEnabled);
+ }
+ }
+
+ private void enableSelectionGroupControls(boolean isEnabled) {
+ selectionGroup.setEnabled(isEnabled);
+ selectionPredicate.setEnabled(isEnabled);
+ selectionTable.setEnabled(isEnabled);
+ selectAllButton.setEnabled(isEnabled);
+ deselectAllButton.setEnabled(isEnabled);
+ TableItem[] tableItems = selectionTable.getItems();
+ int tableItemCount = tableItems.length;
+ for (int index = 0; index < tableItemCount; index++) {
+ tableItems[index].setGrayed(!isEnabled);
+ }
+ if (isEnabled && !isSelectionListPopulated) {
+ populateSelectionTable();
+ }
+ }
+
+ private void enableFilterSpecificationControls(boolean isEnabled) {
+ if (!hideExpressionOption) {
+ if (isEnabled) {
+ expressionRadioButton.setEnabled(true);
+ selectionRadioButton.setEnabled(true);
+ if (expressionRadioButton.getSelection()) {
+ enableSelectionGroupControls(false);
+ enableExpressionGroupControls(true);
+ }
+ else {
+ enableExpressionGroupControls(false);
+ enableSelectionGroupControls(true);
+ }
+ }
+ else {
+ enableExpressionGroupControls(false);
+ enableSelectionGroupControls(false);
+ expressionRadioButton.setEnabled(false);
+ selectionRadioButton.setEnabled(false);
+ }
+ }
+ else {
+ enableSelectionGroupControls(isEnabled);
+ }
+ }
+
+ protected Control createContents(Composite parent) {
+ return createContents(parent, false);
+ }
+
+ protected Control createContents(Composite parent, boolean hideExpressionOption) {
+ this.hideExpressionOption = hideExpressionOption;
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.verticalSpacing = 5;
+ composite.setLayout(layout);
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ GridData gd = null;
+
+ if (hideExpressionOption) {
+ DEFAULT_MESSAGE = SELECTION_ONLY_MESSAGE;
+ setMessage(DEFAULT_MESSAGE);
+ }
+
+ if (!hideExpressionOption) {
+ expressionRadioButton = new Button(composite, SWT.RADIO);
+ expressionRadioButton.setText(resource
+ .queryString("_UI_RADIO_BUTTON_EXPRESSION")); //$NON-NLS-1$
+ gd = new GridData();
+ gd.verticalAlignment = GridData.BEGINNING;
+ expressionRadioButton.setLayoutData(gd);
+
+ expressionGroup = new Group(composite, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 3;
+ layout.verticalSpacing = 5;
+ expressionGroup.setLayout(layout);
+ gd = new GridData(GridData.GRAB_HORIZONTAL
+ | GridData.FILL_HORIZONTAL);
+ gd.verticalAlignment = GridData.BEGINNING;
+ expressionGroup.setLayoutData(gd);
+
+ expressionLabel = new Label(expressionGroup, SWT.NONE);
+ expressionLabel.setText(resource
+ .queryString("_UI_LABEL_EXPRESSION")); //$NON-NLS-1$
+ gd = new GridData();
+ expressionLabel.setLayoutData(gd);
+
+ expressionPredicate = new Combo(expressionGroup, SWT.READ_ONLY);
+ gd = new GridData();
+ gd.verticalAlignment = GridData.BEGINNING;
+ expressionPredicate.setLayoutData(gd);
+ STARTS_WITH_TEXT = resource.queryString("_UI_COMBO_STARTS_WITH"); //$NON-NLS-1$
+ CONTAINS_TEXT = resource.queryString("_UI_COMBO_CONTAINS"); //$NON-NLS-1$
+ ENDS_WITH_TEXT = resource.queryString("_UI_COMBO_ENDS_WITH"); //$NON-NLS-1$
+ NOT_START_WITH_TEXT = resource
+ .queryString("_UI_COMBO_NOT_START_WITH"); //$NON-NLS-1$;
+ NOT_CONTAIN_TEXT = resource.queryString("_UI_COMBO_NOT_CONTAIN"); //$NON-NLS-1$;
+ NOT_END_WITH_TEXT = resource.queryString("_UI_COMBO_NOT_END_WITH"); //$NON-NLS-1$;
+
+ expressionPredicate.add(STARTS_WITH_TEXT);
+ expressionPredicate.add(CONTAINS_TEXT);
+ expressionPredicate.add(ENDS_WITH_TEXT);
+ expressionPredicate.add(NOT_START_WITH_TEXT);
+ expressionPredicate.add(NOT_CONTAIN_TEXT);
+ expressionPredicate.add(NOT_END_WITH_TEXT);
+
+ expressionField = new Text(expressionGroup, SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ expressionField.setLayoutData(gd);
+
+ selectionRadioButton = new Button(composite, SWT.RADIO);
+ selectionRadioButton.setText(resource
+ .queryString("_UI_RADIO_BUTTON_SELECTION")); //$NON-NLS-1$
+ gd = new GridData();
+ gd.verticalAlignment = GridData.BEGINNING;
+ selectionRadioButton.setLayoutData(gd);
+ }
+
+ selectionGroup = new Group(composite, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.verticalSpacing = 5;
+ selectionGroup.setLayout(layout);
+ gd = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL);
+ selectionGroup.setLayoutData(gd);
+
+ selectionPredicate = new Combo(selectionGroup, SWT.READ_ONLY);
+ gd = new GridData();
+ gd.verticalAlignment = GridData.BEGINNING;
+ gd.horizontalSpan = 2;
+ selectionPredicate.setLayoutData(gd);
+ INCLUDE_ITEMS_TEXT = resource.queryString("_UI_COMBO_INCLUDE_ITEMS"); //$NON-NLS-1$
+ EXCLUDE_ITEMS_TEXT = resource.queryString("_UI_COMBO_EXCLUDE_ITEMS"); //$NON-NLS-1$
+ selectionPredicate.add(INCLUDE_ITEMS_TEXT);
+ selectionPredicate.add(EXCLUDE_ITEMS_TEXT);
+
+ selectionTable = new Table(selectionGroup, SWT.CHECK | SWT.BORDER);
+ gd = new GridData(GridData.FILL_BOTH);
+ selectionTable.setLayoutData(gd);
+
+ Composite buttonComposite = new Composite(selectionGroup, SWT.NONE);
+ layout = new GridLayout();
+ layout.numColumns = 1;
+ layout.verticalSpacing = 5;
+ buttonComposite.setLayout(layout);
+ buttonComposite.setLayoutData(new GridData(GridData.FILL_VERTICAL
+ | GridData.VERTICAL_ALIGN_BEGINNING));
+
+ selectAllButton = new Button(buttonComposite, SWT.NONE);
+ selectAllButton.setText(resource.queryString("_UI_BUTTON_SELECT_ALL")); //$NON-NLS-1$
+ selectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
+ | GridData.VERTICAL_ALIGN_BEGINNING));
+
+ deselectAllButton = new Button(buttonComposite, SWT.NONE);
+ deselectAllButton.setText(resource
+ .queryString("_UI_BUTTON_DESELECT_ALL")); //$NON-NLS-1$
+ deselectAllButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
+ | GridData.VERTICAL_ALIGN_BEGINNING));
+
+ disableFilterCheckbox = new Button(composite, SWT.CHECK);
+ disableFilterCheckbox.setText(resource
+ .queryString("_UI_CHECKBOX_DISABLE_FILTER")); //$NON-NLS-1$
+ gd = new GridData();
+ gd.verticalAlignment = GridData.BEGINNING;
+ disableFilterCheckbox.setLayoutData(gd);
+
+ initializeDialogUnits(composite);
+ setValid(validatePage());
+
+ disableFilterCheckbox.addListener(SWT.Selection, this);
+ if (!hideExpressionOption) {
+ expressionRadioButton.addListener(SWT.Selection, this);
+ selectionRadioButton.addListener(SWT.Selection, this);
+ expressionField.addListener(SWT.Modify, this);
+ }
+ selectionTable.addListener(SWT.Selection, this);
+ selectionPredicate.addListener(SWT.Selection, this);
+ selectAllButton.addListener(SWT.Selection, this);
+ deselectAllButton.addListener(SWT.Selection, this);
+
+ disableFilterCheckbox.setSelection(false);
+ if (!hideExpressionOption) {
+ expressionRadioButton.setSelection(true);
+ expressionPredicate.select(expressionPredicate
+ .indexOf(STARTS_WITH_TEXT));
+ selectionPredicate.select(selectionPredicate
+ .indexOf(INCLUDE_ITEMS_TEXT));
+ enableSelectionGroupControls(false);
+ }
+ else {
+ selectionPredicate.select(selectionPredicate
+ .indexOf(INCLUDE_ITEMS_TEXT));
+ }
+ initializeValues();
+ validatePage();
+
+ return composite;
+ }
+
+ protected void initializeValues() {
+ isSelectionListPopulated = false;
+ selectionTable.removeAll();
+
+ ConnectionFilter connFilter = getConnectionFilter();
+
+ if (connFilter != null) {
+ disableFilterCheckbox.setSelection(false);
+ String predicate = connFilter.getPredicate();
+ if (!hideExpressionOption && isPredicateAnExpression(predicate)) {
+ expressionRadioButton.setSelection(true);
+ selectionRadioButton.setSelection(false);
+ expressionPredicate.select(expressionPredicate
+ .indexOf(findExpressionPredicate(predicate)));
+ expressionField.setText(findExpressionValue(predicate));
+ enableFilterSpecificationControls(true);
+ }
+ else {
+ if (!hideExpressionOption) {
+ selectionRadioButton.setSelection(true);
+ expressionRadioButton.setSelection(false);
+ }
+ if (isPredicateNegated(predicate)) {
+ selectionPredicate.select(selectionPredicate
+ .indexOf(EXCLUDE_ITEMS_TEXT));
+ }
+ populateSelectionTable();
+ selectSelectionFilterItems(findSelectionFilterItems(predicate));
+ enableFilterSpecificationControls(true);
+ }
+ }
+ else {
+ disableFilterCheckbox.setSelection(true);
+ enableFilterSpecificationControls(false);
+ }
+ }
+
+ private String[] findSelectionFilterItems(String filterPredicate) {
+ String[] filterItems = {};
+ if (filterPredicate != null) {
+ String[] predicateSubStrings = filterPredicate
+ .split(IDENTIFIER_DELIMITER);
+ // Remove first and last items from array
+ int predicateSubStringsCount = predicateSubStrings.length;
+ Vector filterItemCollection = new Vector();
+ for (int index = 1; index < (predicateSubStringsCount - 1); index++) {
+ filterItemCollection.add(predicateSubStrings[index]);
+ }
+ filterItems = new String[filterItemCollection.size()];
+ filterItemCollection.copyInto(filterItems);
+ }
+ return filterItems;
+ }
+
+ private void selectSelectionFilterItems(String[] filterItems) {
+ TableItem[] tableItems = selectionTable.getItems();
+ Hashtable tableItemsCollection = new Hashtable();
+ int tableItemsCount = tableItems.length;
+ for (int index = 0; index < tableItemsCount; index++) {
+ tableItemsCollection.put(tableItems[index].getText(),
+ tableItems[index]);
+ }
+ int filterItemsCount = filterItems.length;
+ for (int index = 0; index < filterItemsCount; index++) {
+ Object tableItem = tableItemsCollection.get(filterItems[index]);
+ if (tableItem != null) {
+ ((TableItem) tableItem).setChecked(true);
+ }
+ }
+ }
+
+ private boolean isPredicateAnExpression(String filterPredicate) {
+ boolean isExpression = false;
+ if (filterPredicate != null
+ && filterPredicate.split(IDENTIFIER_DELIMITER)[0]
+ .indexOf(LIKE_PREDICATE_TEXT) != -1) {
+ isExpression = true;
+ }
+ return isExpression;
+ }
+
+ private boolean isPredicateNegated(String filterPredicate) {
+ boolean isNegated = false;
+ if (filterPredicate != null
+ && filterPredicate.split(IDENTIFIER_DELIMITER)[0]
+ .indexOf(NOT_PREDICATE_TEXT) != -1) {
+ isNegated = true;
+ }
+ return isNegated;
+ }
+
+ private String findExpressionValue(String filterPredicate) {
+ String expressionValue = filterPredicate.split(IDENTIFIER_DELIMITER)[1];
+ if (expressionValue.startsWith("%")) { //$NON-NLS-1$
+ expressionValue = expressionValue.substring(1);
+ }
+
+ if (expressionValue.endsWith("%")) { //$NON-NLS-1$
+ expressionValue = expressionValue.substring(0, (expressionValue
+ .length() - 1));
+ }
+
+ return expressionValue;
+ }
+
+ private String findExpressionPredicate(String filterPredicate) {
+ String expressionPredicate = CONTAINS_TEXT;
+ boolean isNotLike = false;
+ boolean startsWithPercentSign = false;
+ boolean endsWithPercentSign = false;
+ if (filterPredicate.startsWith(NOT_PREDICATE_TEXT)) {
+ isNotLike = true;
+ }
+ String expressionValue = filterPredicate.split(IDENTIFIER_DELIMITER)[1];
+ if (expressionValue.startsWith("%")) { //$NON-NLS-1$
+ startsWithPercentSign = true;
+ }
+
+ if (expressionValue.endsWith("%")) { //$NON-NLS-1$
+ endsWithPercentSign = true;
+ }
+
+ if (startsWithPercentSign && endsWithPercentSign) {
+ if (isNotLike) {
+ expressionPredicate = NOT_CONTAIN_TEXT;
+ }
+ else {
+ expressionPredicate = CONTAINS_TEXT;
+ }
+ }
+ else if (startsWithPercentSign) {
+ if (isNotLike) {
+ expressionPredicate = NOT_END_WITH_TEXT;
+ }
+ else {
+ expressionPredicate = ENDS_WITH_TEXT;
+ }
+ }
+ else if (endsWithPercentSign) {
+ if (isNotLike) {
+ expressionPredicate = NOT_START_WITH_TEXT;
+ }
+ else {
+ expressionPredicate = STARTS_WITH_TEXT;
+ }
+ }
+ return expressionPredicate;
+ }
+
+ protected boolean validatePage() {
+ boolean isValid = true;
+ if (!disableFilterCheckbox.getSelection()) {
+ if (!hideExpressionOption && expressionRadioButton.getSelection()) {
+ if (expressionField.getText().length() == 0) {
+ this.setMessage(resource
+ .queryString("_UI_MESSAGE_CRITERIA_REQUIRED")); //$NON-NLS-1$
+ this.setErrorMessage(null);
+ isValid = false;
+ }
+ else if ((expressionField.getText().indexOf(
+ IDENTIFIER_DELIMITER) > -1)
+ || (expressionField.getText().indexOf('"') > -1)) {
+ this.setErrorMessage(resource
+ .queryString("_UI_MESSAGE_NO_QUOTES")); //$NON-NLS-1$
+ this.setMessage(DEFAULT_MESSAGE);
+ isValid = false;
+ }
+ }
+ else {
+ TableItem[] items = selectionTable.getItems();
+ int itemCount = items.length;
+ boolean isItemSelected = false;
+ for (int index = 0; index < itemCount; index++) {
+ if (items[index].getChecked()) {
+ isItemSelected = true;
+ break;
+ }
+ }
+ if (!isItemSelected) {
+ this.setMessage(resource
+ .queryString("_UI_MESSAGE_SELECTION_REQUIRED")); //$NON-NLS-1$
+ this.setErrorMessage(null);
+ isValid = false;
+ }
+ }
+ }
+ if (isValid) {
+ setMessage(DEFAULT_MESSAGE);
+ setErrorMessage(null);
+
+ }
+ return isValid;
+ }
+
+ public String getPredicate() {
+ String predicate = ""; //$NON-NLS-1$
+ if (isFilterSpecified()) {
+ if (!hideExpressionOption && expressionRadioButton.getSelection()) {
+ String selectedPredicate = expressionPredicate
+ .getItem(expressionPredicate.getSelectionIndex());
+ String cleanedString = expressionField.getText().trim();
+ if (selectedPredicate.equals(STARTS_WITH_TEXT)) {
+ predicate = LIKE_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER + cleanedString + "%" //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER;
+ }
+ else if (selectedPredicate.equals(NOT_START_WITH_TEXT)) {
+ predicate = NOT_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + LIKE_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER + cleanedString + "%" //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER;
+ }
+ else if (selectedPredicate.equals(CONTAINS_TEXT)) {
+ predicate = LIKE_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER + "%" + cleanedString + "%" //$NON-NLS-1$ //$NON-NLS-2$
+ + IDENTIFIER_DELIMITER;
+ }
+ else if (selectedPredicate.equals(NOT_CONTAIN_TEXT)) {
+ predicate = NOT_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + LIKE_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER + "%" + cleanedString + "%" //$NON-NLS-1$ //$NON-NLS-2$
+ + IDENTIFIER_DELIMITER;
+ }
+ else if (selectedPredicate.equals(ENDS_WITH_TEXT)) {
+ predicate = LIKE_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER + "%" + cleanedString //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER;
+ }
+ else if (selectedPredicate.equals(NOT_END_WITH_TEXT)) {
+ predicate = NOT_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + LIKE_PREDICATE_TEXT + " " //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER + "%" + cleanedString //$NON-NLS-1$
+ + IDENTIFIER_DELIMITER;
+ }
+ }
+ else {
+ String itemList = ""; //$NON-NLS-1$
+
+ // Generate Item list
+ TableItem[] items = selectionTable.getItems();
+ Vector selectedItemsCollection = new Vector();
+ int itemCount = items.length;
+ for (int index = 0; index < itemCount; index++) {
+ if (items[index].getChecked()) {
+ selectedItemsCollection.add(items[index]);
+ }
+ }
+ TableItem[] selectedItems = new TableItem[selectedItemsCollection
+ .size()];
+ selectedItemsCollection.copyInto(selectedItems);
+ int selectedItemCount = selectedItems.length;
+ if (selectedItemCount > 0) {
+ itemList = itemList + IDENTIFIER_DELIMITER
+ + selectedItems[0].getText() + IDENTIFIER_DELIMITER;
+ for (int index = 1; index < selectedItemCount; index++) {
+ itemList = itemList + ", " + IDENTIFIER_DELIMITER //$NON-NLS-1$
+ + selectedItems[index].getText()
+ + IDENTIFIER_DELIMITER;
+ }
+ predicate = IN_PREDICATE_TEXT + "(" + itemList + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+ if (selectionPredicate.getItem(
+ selectionPredicate.getSelectionIndex()).equals(
+ EXCLUDE_ITEMS_TEXT)) {
+ predicate = NOT_PREDICATE_TEXT + " " + predicate; //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ return predicate;
+ }
+
+ public boolean isFilterSpecified() {
+ return !disableFilterCheckbox.getSelection();
+ }
+
+ public boolean isIncludeSelected() {
+ if (selectionPredicate.getItem(selectionPredicate.getSelectionIndex())
+ .equals(INCLUDE_ITEMS_TEXT)) {
+ return true;
+ }
+ return false;
+ }
+
+ private EObject getParentEObject(Object current) {
+ while (!(current instanceof EObject)
+ && (current = ((IVirtualNode) current).getParent()) != null)
+ ;
+ return (EObject) current;
+ }
+
+ protected void populateSelectionTable() {
+ if (selection != null) {
+ Object sel = ((StructuredSelection) selection).getFirstElement();
+ selectionTable.removeAll();
+ if (sel instanceof IVirtualNode) {
+ if (sel instanceof ISchemaNode) {
+ Iterator schemas = Arrays.asList(
+ ((ISchemaNode) sel).getChildrenArray()).iterator();
+ while (schemas.hasNext()) {
+ TableItem tableItem = new TableItem(selectionTable,
+ SWT.NONE);
+ tableItem.setText(((SQLObject) schemas.next())
+ .getName());
+ }
+ }
+ else {
+ ContainmentService containmentService = RDBCorePlugin
+ .getDefault().getContainmentService();
+ EObject schema = (EObject) getParentEObject(sel);
+ Collection viewsCollection = containmentService
+ .getContainedDisplayableElements(schema,
+ ((IVirtualNode) sel).getGroupID());
+
+ Iterator views = viewsCollection.iterator();
+ while (views.hasNext()) {
+ TableItem tableItem = new TableItem(selectionTable,
+ SWT.NONE);
+ tableItem.setText(((SQLObject) views.next()).getName());
+ }
+ }
+ isSelectionListPopulated = true;
+ }
+ }
+ }
+
+ protected abstract ConnectionFilter getConnectionFilter();
+
+ protected abstract IConnectionProfile getConnectionProfile();
+
+ protected abstract String getConnectionFilterType();
+
+ public boolean performOk() {
+ String filterType = getConnectionFilterType();
+ if (filterType != null) {
+ IConnectionProfile profile = getConnectionProfile();
+ String filterPropKey = ConnectionFilter.FILTER_PROP_PREFIX+filterType;
+ Properties props = profile.getBaseProperties();
+ props.setProperty(filterPropKey,getPredicate());
+ profile.setBaseProperties(props);
+ }
+ return true;
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultFilterPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultFilterPropertyPage.java
new file mode 100644
index 0000000..c8c283f
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultFilterPropertyPage.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: rcernich - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilter;
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilterImpl;
+
+public abstract class DefaultFilterPropertyPage extends ConnectionFilterPropertyPage {
+
+ public DefaultFilterPropertyPage() {
+ super();
+ }
+
+ protected ConnectionFilter getConnectionFilter() {
+ IConnectionProfile profile = getConnectionProfile();
+ if (profile == null) {
+ return null;
+ }
+
+ String predicate = profile.getBaseProperties()
+ .getProperty(
+ ConnectionFilter.FILTER_PROP_PREFIX
+ + getConnectionFilterType());
+ if (predicate == null || predicate.length() == 0) {
+ return null;
+ }
+ return new ConnectionFilterImpl(predicate);
+ }
+
+ protected IConnectionProfile getConnectionProfile() {
+ IAdaptable element = getElement();
+ if (element instanceof IConnectionProfile) {
+ return (IConnectionProfile) element;
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultSPFilterPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultSPFilterPropertyPage.java
new file mode 100644
index 0000000..49e68c5
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultSPFilterPropertyPage.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: rcernich - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilter;
+
+public class DefaultSPFilterPropertyPage extends DefaultFilterPropertyPage {
+
+ public DefaultSPFilterPropertyPage() {
+ super();
+ }
+
+ protected String getConnectionFilterType() {
+ return ConnectionFilter.STORED_PROCEDURE_FILTER;
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultTableFilterPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultTableFilterPropertyPage.java
new file mode 100644
index 0000000..6779875
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/DefaultTableFilterPropertyPage.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: rcernich - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilter;
+
+public class DefaultTableFilterPropertyPage extends DefaultFilterPropertyPage {
+
+ public DefaultTableFilterPropertyPage() {
+ super();
+ }
+
+ protected String getConnectionFilterType() {
+ return ConnectionFilter.TABLE_FILTER;
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/FilterNodeFilterPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/FilterNodeFilterPropertyPage.java
new file mode 100644
index 0000000..bdcdedf
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/FilterNodeFilterPropertyPage.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2001, 2004 IBM Corporation and others. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.datatools.connectivity.IConnection;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilter;
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionInfo;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+/**
+ * @author ledunnel
+ */
+public class FilterNodeFilterPropertyPage extends ConnectionFilterPropertyPage {
+
+ public FilterNodeFilterPropertyPage() {
+ super();
+ }
+
+ public void setElement(IAdaptable element) {
+ super.setElement(element);
+ // The following is for backward compatibility for those relying on
+ IFilterNode filterNode = getFilterNode();
+ if (filterNode == null) {
+ selection = null;
+ }
+ else {
+ selection = new StructuredSelection(filterNode);
+ }
+ }
+
+ protected ConnectionFilter getConnectionFilter() {
+ IFilterNode filterNode = getFilterNode();
+ if (filterNode == null) {
+ return null;
+ }
+
+ ConnectionInfo connection = filterNode.getParentConnection();
+ if (connection == null) {
+ return null;
+ }
+ return connection.getFilter(filterNode.getFilterName());
+ }
+
+ protected IConnectionProfile getConnectionProfile() {
+ IFilterNode filterNode = getFilterNode();
+ if (filterNode == null) {
+ return null;
+ }
+
+ ConnectionInfo connection = filterNode.getParentConnection();
+ if (connection instanceof IConnection) {
+ return ((IConnection)connection).getConnectionProfile();
+ }
+ return null;
+ }
+
+ protected IFilterNode getFilterNode() {
+ IAdaptable element = this.getElement();
+ IFilterNode filterNode = (IFilterNode) element
+ .getAdapter(IFilterNode.class);
+ if (filterNode == null) {
+ filterNode = (IFilterNode) Platform.getAdapterManager()
+ .loadAdapter(element, IFilterNode.class.getName());
+ }
+ return filterNode;
+ }
+
+ protected String getConnectionFilterType() {
+ IFilterNode filterNode = getFilterNode();
+ if (filterNode == null) {
+ return null;
+ }
+ return filterNode.getFilterName();
+ }
+
+}
\ No newline at end of file
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/IFilterNode.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/IFilterNode.java
index 2124a8f..90a80e4 100644
--- a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/IFilterNode.java
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/IFilterNode.java
@@ -10,10 +10,12 @@
*******************************************************************************/
package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+import org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.virtual.IVirtualNode;
+
/**
* @author ljulien
*/
-public interface IFilterNode
+public interface IFilterNode extends IVirtualNode
{
public final static String SEPARATOR = "::"; //$NON-NLS-1$
public String getFilterName ();
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/SchemaFilterPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/SchemaFilterPropertyPage.java
new file mode 100644
index 0000000..da18422
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/explorer/filter/SchemaFilterPropertyPage.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Sybase, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: rcernich - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.datatools.connectivity.sqm.core.internal.ui.explorer.filter;
+
+import org.eclipse.datatools.connectivity.sqm.internal.core.connection.ConnectionFilter;
+
+public class SchemaFilterPropertyPage extends DefaultFilterPropertyPage {
+
+ public SchemaFilterPropertyPage() {
+ super();
+ }
+
+ protected String getConnectionFilterType() {
+ return ConnectionFilter.SCHEMA_FILTER;
+ }
+
+}
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/l10n/datatoolsCoreUI.properties b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/l10n/datatoolsCoreUI.properties
index cdc6a26..018f7e1 100644
--- a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/l10n/datatoolsCoreUI.properties
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/l10n/datatoolsCoreUI.properties
@@ -166,3 +166,27 @@
_UI_DEFAULT_MSG_NEW_ALLOWED = &Enter or select the parent folder:
_UI_DEFAULT_MSG_SELECT_ONLY = Select the folder:
+#
+## Filter Dialog
+#
+_UI_TITLE_FILTER = Specify Filter
+_UI_DESCRIPTION_FILTER = Specify a filter by selecting a predicate and entering a value or by indicating whether to include or exclude a selection of items.
+_UI_DESCRIPTION_SELECTION_ONLY = Specify a filter by indicating whether to include or exclude a selection of items.
+_UI_RADIO_BUTTON_EXPRESSION = &Expression
+_UI_LABEL_EXPRESSION = N&ame
+_UI_COMBO_STARTS_WITH = Starts with the characters
+_UI_COMBO_NOT_START_WITH = Does not start with the characters
+_UI_COMBO_CONTAINS = Contains the characters
+_UI_COMBO_NOT_CONTAIN = Does not contain the characters
+_UI_COMBO_ENDS_WITH = Ends with the characters
+_UI_COMBO_NOT_END_WITH = Does not end with the characters
+_UI_RADIO_BUTTON_SELECTION = Se&lection
+_UI_COMBO_INCLUDE_ITEMS = Include selected items
+_UI_COMBO_EXCLUDE_ITEMS = Exclude selected items
+_UI_BUTTON_SELECT_ALL = &Select All
+_UI_BUTTON_DESELECT_ALL = &Deselect All
+_UI_CHECKBOX_DISABLE_FILTER = D&isable filter
+_UI_MESSAGE_CRITERIA_REQUIRED = Please specify filtering criteria.
+_UI_MESSAGE_NO_QUOTES = The expression value must not contain quotes.
+_UI_MESSAGE_SELECTION_REQUIRED = Please select at least one item.
+
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/util/resources/ResourceLoader.java b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/util/resources/ResourceLoader.java
index d869949..6198ab3 100644
--- a/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/util/resources/ResourceLoader.java
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core.ui/src/org/eclipse/datatools/connectivity/sqm/core/internal/ui/util/resources/ResourceLoader.java
@@ -141,7 +141,7 @@
}
catch (Throwable e)
{
- return NO_RESOURCE_FOUND;
+ return stringID;
}
}
}
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionFilter.java b/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionFilter.java
index 3b6c507..177378d 100644
--- a/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionFilter.java
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionFilter.java
@@ -73,4 +73,10 @@
public static final String DISCOVERED_SERVER_FILTER = "DatatoolsDiscoveredServerFilterPredicate"; //$NON-NLS-1$
public static final String XSR_OBJECTS_FILTER = "DatatoolsXMLSchemasFilterPredicate"; //$NON-NLS-1$
public static final String XML_SCHEMA_DOC_FILTER = "DatatoolsXMLSchemaDocsFilterPredicate"; //$NON-NLS-1$
+
+ public static final String FILTER_PROP_PREFIX = "org.eclipse.datatools.connectivity.filter.";
+ public static final String SCHEMA_FILTER_PROP_ID = FILTER_PROP_PREFIX+ConnectionFilter.SCHEMA_FILTER;
+ public static final String DEFAULT_TABLE_FILTER_PROP_ID = FILTER_PROP_PREFIX+ConnectionFilter.TABLE_FILTER;
+ public static final String DEFAULT_STORED_PROCEDURE_FILTER_PROP_ID = FILTER_PROP_PREFIX+ConnectionFilter.STORED_PROCEDURE_FILTER;
+
}
diff --git a/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionInfoImpl.java b/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionInfoImpl.java
index 92c3fbd..01a85f5 100644
--- a/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionInfoImpl.java
+++ b/plugins/org.eclipse.datatools.connectivity.sqm.core/src/org/eclipse/datatools/connectivity/sqm/internal/core/connection/ConnectionInfoImpl.java
@@ -57,6 +57,9 @@
public class ConnectionInfoImpl extends VersionProviderConnection implements ConnectionInfo {
+
+ private static Map sDatabaseToConnectionInfo = new HashMap();
+
private static final String PASSWORD = "password"; //$NON-NLS-1$
private static final String USER = "user"; //$NON-NLS-1$
@@ -79,6 +82,17 @@
private IConnection jdbcConnection;
public static final String TECHNOLOGY_ROOT_KEY = "jdbc"; //$NON-NLS-1$
+
+ public static ConnectionInfo getConnectionInfoForDatabase(Database database) {
+ ConnectionInfo connection = null;
+ synchronized (sDatabaseToConnectionInfo) {
+ if (sDatabaseToConnectionInfo.containsKey(database)) {
+ connection = (ConnectionInfo) sDatabaseToConnectionInfo
+ .get(database);
+ }
+ }
+ return connection;
+ }
public String getName() {
return this.name;
@@ -241,6 +255,9 @@
else {
if(this.sharedDatabase == null) {
this.sharedDatabase = database;
+
+ addDatabaseToConnectionInfoMapEntry();
+
Collection c = new LinkedList();
c.addAll(this.listeners);
Iterator it = c.iterator();
@@ -267,6 +284,9 @@
public void removeSharedDatabase() {
if(this.sharedDatabase == null) throw new IllegalStateException();
Database database = this.sharedDatabase;
+
+ removeDatabaseToConnectionInfoMapEntry();
+
this.sharedDatabase = null;
Collection c = new LinkedList();
c.addAll(this.listeners);
@@ -282,6 +302,18 @@
}
}
+ private void addDatabaseToConnectionInfoMapEntry() {
+ synchronized (sDatabaseToConnectionInfo) {
+ sDatabaseToConnectionInfo.put(getSharedDatabase(), this);
+ }
+ }
+
+ private void removeDatabaseToConnectionInfoMapEntry() {
+ synchronized (sDatabaseToConnectionInfo) {
+ sDatabaseToConnectionInfo.remove(getSharedDatabase());
+ }
+ }
+
public boolean addConnectionSharingListener(ConnectionSharingListener listener) {
if(listener == null) throw new NullPointerException();
Iterator it = this.listeners.iterator();
@@ -642,6 +674,9 @@
}
public void close() {
+ if (getSharedDatabase() != null) {
+ setSharedDatabase(null);
+ }
if (getSharedConnection() != null) {
setSharedConnection(null);
}
diff --git a/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfileDetailsPropertyPage.java b/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfileDetailsPropertyPage.java
index 293a866..6bd2ecd 100644
--- a/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfileDetailsPropertyPage.java
+++ b/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfileDetailsPropertyPage.java
@@ -10,29 +10,21 @@
******************************************************************************/
package org.eclipse.datatools.connectivity.ui.wizards;
-import java.util.Iterator;
-import java.util.Properties;
-
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.internal.ConnectionProfile;
import org.eclipse.datatools.connectivity.internal.ui.ConnectivityUIPlugin;
import org.eclipse.datatools.connectivity.internal.ui.IHelpConstants;
import org.eclipse.datatools.connectivity.ui.PingJob;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.PropertyPage;
/**
* Base property page implementation for connection profiles.
@@ -42,7 +34,11 @@
*
* @author shongxum
*/
-public abstract class ProfileDetailsPropertyPage extends PropertyPage {
+public abstract class ProfileDetailsPropertyPage extends ProfilePropertyPage {
+
+ protected ProfileDetailsPropertyPage() {
+ super(true);
+ }
/*
* (non-Javadoc)
@@ -50,18 +46,7 @@
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
protected Control createContents(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- final GridLayout gridLayout = new GridLayout();
- gridLayout.horizontalSpacing = 0;
- gridLayout.marginWidth = 0;
- gridLayout.marginHeight = 0;
- container.setLayout(gridLayout);
-
- final Composite composite = new Composite(container, SWT.NONE);
- composite.setLayout(new FillLayout());
- composite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- createCustomContents(composite);
+ Composite container = (Composite)super.createContents(parent);
final Button button = new Button(container, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
@@ -79,17 +64,6 @@
return container;
}
- protected abstract void createCustomContents(Composite parent);
-
- protected abstract Properties collectProperties();
-
- protected IConnectionProfile getConnectionProfile() {
- IAdaptable element = getElement();
- IConnectionProfile profile = (IConnectionProfile) element
- .getAdapter(IConnectionProfile.class);
- return profile;
- }
-
protected void testConnection() {
IConnectionProfile cp = getConnectionProfile();
ConnectionProfile profile = new ConnectionProfile(cp.getName(), cp
@@ -112,38 +86,4 @@
});
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.preference.IPreferencePage#performOk()
- */
- public boolean performOk() {
- IConnectionProfile profile = getConnectionProfile();
- Properties oldProps = profile.getBaseProperties();
- Properties newProps = collectProperties();
- Object key, oldObj, newObj;
- boolean changed = false;
- for (Iterator itr = oldProps.keySet().iterator(); itr.hasNext();) {
- key = itr.next();
- oldObj = oldProps.get(key);
- newObj = newProps.get(key);
- if (!oldObj.equals(newObj)) {
- changed = true;
- break;
- }
- }
- profile.setBaseProperties(newProps);
- if (changed && profile.isConnected()) {
- if (MessageDialog.openQuestion(getShell(), ConnectivityUIPlugin
- .getDefault().getResourceString(
- "ConnectionProfileDetailsPage.AskConfirmation"),
- ConnectivityUIPlugin.getDefault().getResourceString(
- "ConnectionProfileDetailsPage.AskReconnect"))) {
- profile.disconnect(null);
- profile.connect(null);
- }
- }
- return super.performOk();
- }
-
}
diff --git a/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfilePropertyPage.java b/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfilePropertyPage.java
new file mode 100644
index 0000000..af0b972
--- /dev/null
+++ b/plugins/org.eclipse.datatools.connectivity.ui/src/org/eclipse/datatools/connectivity/ui/wizards/ProfilePropertyPage.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Sybase, Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: shongxum - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.datatools.connectivity.ui.wizards;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.internal.ui.ConnectivityUIPlugin;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+/**
+ * Base property page implementation for connection profiles.
+ *
+ * This implementation takes care of updating the connection profile when
+ * OK is pressed.
+ *
+ * @author shongxum
+ */
+public abstract class ProfilePropertyPage extends PropertyPage {
+
+ private boolean mAffectsConnectionProperties;
+
+ protected ProfilePropertyPage() {
+ this(false);
+ }
+
+ protected ProfilePropertyPage(boolean affectsConnectionProperties) {
+ super();
+ mAffectsConnectionProperties = affectsConnectionProperties;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+ */
+ protected Control createContents(Composite parent) {
+ Composite container = new Composite(parent, SWT.NULL);
+ final GridLayout gridLayout = new GridLayout();
+ gridLayout.horizontalSpacing = 0;
+ gridLayout.marginWidth = 0;
+ gridLayout.marginHeight = 0;
+ container.setLayout(gridLayout);
+
+ final Composite composite = new Composite(container, SWT.NONE);
+ composite.setLayout(new FillLayout());
+ composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ createCustomContents(composite);
+
+ return container;
+ }
+
+ protected abstract void createCustomContents(Composite parent);
+
+ protected abstract Properties collectProperties();
+
+ protected IConnectionProfile getConnectionProfile() {
+ IAdaptable element = getElement();
+ IConnectionProfile profile = (IConnectionProfile) element
+ .getAdapter(IConnectionProfile.class);
+ return profile;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.IPreferencePage#performOk()
+ */
+ public boolean performOk() {
+ IConnectionProfile profile = getConnectionProfile();
+ Properties oldProps = profile.getBaseProperties();
+ Properties newProps = collectProperties();
+
+ boolean changed = false;
+ for (Iterator itr = newProps.keySet().iterator(); !changed
+ && itr.hasNext();) {
+ Object key = itr.next();
+ Object oldObj = oldProps.get(key);
+ Object newObj = newProps.get(key);
+ changed = (newObj != null && !newObj.equals(oldObj))
+ || (newObj == null && oldObj != null);
+ }
+
+ if (changed) {
+ oldProps.putAll(newProps);
+ profile.setBaseProperties(oldProps);
+
+ if (mAffectsConnectionProperties && profile.isConnected()) {
+ if (MessageDialog
+ .openQuestion(
+ getShell(),
+ ConnectivityUIPlugin
+ .getDefault()
+ .getResourceString(
+ "ConnectionProfileDetailsPage.AskConfirmation"),
+ ConnectivityUIPlugin
+ .getDefault()
+ .getResourceString(
+ "ConnectionProfileDetailsPage.AskReconnect"))) {
+ profile.disconnect(null);
+ profile.connect(null);
+ }
+ }
+ }
+
+ return super.performOk();
+ }
+
+}