[Ds-java-dev] svn commit r17008 -
in trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide:
dialog wizard
Lahiru Sandakith
sandakith at wso2.com
Wed May 14 23:24:18 PDT 2008
Congratulations SamindaW !!
Great improvement and neat clean first contribution. Party Time ;) Just
Kidding..
svn at wso2.org wrote:
> Author: samindaw
> Date: Wed May 14 22:26:11 2008
> New Revision: 17008
>
> Log:
> add/edit/delete query data, input/output mapping to the ds xml
>
> Modified:
> trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddInputParamDialog.java
> trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddOutputMappingDialog.java
> trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddQueryDialog.java
> trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/wizard/WSO2DataserviceWizardStepTwo.java
>
> Modified: trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddInputParamDialog.java
> ==============================================================================
> --- trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddInputParamDialog.java (original)
> +++ trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddInputParamDialog.java Wed May 14 22:26:11 2008
> @@ -28,6 +28,10 @@
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
> import org.wso2.ws.dataservice.ide.util.FontUtil;
> +import org.wso2.ws.dataservice.ide.wizard.WSO2DataserviceWizardStepTwo;
> +
> +import java.util.List;
> +import java.util.ArrayList;
>
> /**
> * Dialog represent the Add Input Parameter configuration UI
> @@ -36,11 +40,24 @@
>
> private Combo sqlTypeCombo;
> private Combo inOutTypeCombo;
> -
> + private List mappingData;
> +
> + private Text nameText;
> + private Text ordinalText;
> +
> public AddInputParamDialog(Shell parentShell) {
> super(parentShell);
> + mappingData=new ArrayList();
> + resetMappingData();
> }
>
> + private void resetMappingData(){
> + mappingData.clear();
> + mappingData.add("");
> + mappingData.add("");
> + mappingData.add("");
> + mappingData.add("");
> + }
> /**
> * Create the dialog area with the controls
> */
> @@ -77,7 +94,7 @@
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> nameText.setLayoutData(gd);
> @@ -122,14 +139,14 @@
> comboChanged();
> }
> });
> -
> +
> label = new Label(container, SWT.NULL);
> label.setText("Ordinal **");
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text ordinalText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + ordinalText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> ordinalText.setLayoutData(gd);
> @@ -144,11 +161,15 @@
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 3;
> label.setLayoutData(gd);
> -
> + comboChanged();
> return super.createDialogArea(parent);
> }
>
> private void pathChanged() {
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_IMAP_NAME,
> + nameText.getText().trim());
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_IMAP_ORDINAL,
> + ordinalText.getText().trim());
> //update the data model
> }
>
> @@ -177,9 +198,19 @@
> * Handle the Combo Changed scenario
> */
> private void comboChanged() {
> + if (sqlTypeCombo.getSelectionIndex()>-1)
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_IMAP_SQL_TYPE,
> + sqlTypeCombo.getItem(sqlTypeCombo.getSelectionIndex()).trim());
> + if (inOutTypeCombo.getSelectionIndex()>-1)
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_IMAP_INOUT_TYPE,
> + inOutTypeCombo.getItem(inOutTypeCombo.getSelectionIndex()).trim());
> //Combo updated
> }
>
> + public List getMappingData(){
> + return mappingData;
> + }
> +
> }
>
>
>
> Modified: trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddOutputMappingDialog.java
> ==============================================================================
> --- trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddOutputMappingDialog.java (original)
> +++ trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddOutputMappingDialog.java Wed May 14 22:26:11 2008
> @@ -15,6 +15,9 @@
> */
> package org.wso2.ws.dataservice.ide.dialog;
>
> +import java.util.ArrayList;
> +import java.util.List;
> +
> import org.eclipse.jface.dialogs.Dialog;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.events.ModifyEvent;
> @@ -28,6 +31,7 @@
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
> import org.wso2.ws.dataservice.ide.util.FontUtil;
> +import org.wso2.ws.dataservice.ide.wizard.WSO2DataserviceWizardStepTwo;
>
> /**
> * Dialog represent the Add Output Mapping configuration UI
> @@ -35,9 +39,23 @@
> public class AddOutputMappingDialog extends Dialog{
>
> private Combo mappingTypeCombo;
> -
> + private List mappingData;
> +
> + private Text sqlColumnNameText;
> + private Text outputFieldNameText;
> +
> public AddOutputMappingDialog(Shell parentShell) {
> super(parentShell);
> + mappingData=new ArrayList();
> + resetMappingData();
> + }
> +
> + private void resetMappingData(){
> + mappingData.clear();
> + mappingData.add("");
> + mappingData.add("");
> + mappingData.add("");
> + mappingData.add("");
> }
>
> /**
> @@ -88,19 +106,20 @@
> }
> });
>
> +
> label = new Label(container, SWT.NULL);
> label.setText("Output Field Name");
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text outputFieldNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + outputFieldNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> outputFieldNameText.setLayoutData(gd);
> outputFieldNameText.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent e) {
> - //pathChanged();
> + pathChanged();
> }
> });
>
> @@ -110,16 +129,16 @@
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text sqlColumnNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + sqlColumnNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> sqlColumnNameText.setLayoutData(gd);
> sqlColumnNameText.addModifyListener(new ModifyListener() {
> public void modifyText(ModifyEvent e) {
> - //pathChanged();
> + pathChanged();
> }
> });
> -
> + comboChanged();
> return super.createDialogArea(parent);
> }
>
> @@ -132,12 +151,24 @@
> mappingTypeCombo.add("ATTRIBUTE");
> }
>
> -
> + private void pathChanged() {
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_OMAP_SQL_COL,
> + sqlColumnNameText.getText().trim());
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_OMAP_OUT_FIELD,
> + outputFieldNameText.getText().trim());
> + //update the data model
> + }
> +
> /**
> * Ensures that both text fields are set.
> */
> private void comboChanged() {
> - //validate the plug-in
> + if (mappingTypeCombo.getSelectionIndex()>-1)
> + mappingData.set(WSO2DataserviceWizardStepTwo.SQLQUERY_OMAP_TYPE,
> + mappingTypeCombo.getItem(mappingTypeCombo.getSelectionIndex()).trim());
> + }
> +
> + public List getMappingData(){
> + return mappingData;
> }
> -
> }
> \ No newline at end of file
>
> Modified: trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddQueryDialog.java
> ==============================================================================
> --- trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddQueryDialog.java (original)
> +++ trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/dialog/AddQueryDialog.java Wed May 14 22:26:11 2008
> @@ -37,14 +37,16 @@
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Label;
> +import org.eclipse.swt.widgets.MessageBox;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
> import org.wso2.ws.dataservice.ide.WSO2DataservicePlugin;
> +import org.wso2.ws.dataservice.ide.constant.WSO2DataserviceWizardConstant;
> import org.wso2.ws.dataservice.ide.context.PersistentDSContext;
> -import org.wso2.ws.dataservice.ide.util.DataServiceXMLUtil;
> import org.wso2.ws.dataservice.ide.util.FontUtil;
> import org.wso2.ws.dataservice.ide.wizard.WSO2DataserviceWizardStepTwo;
>
> +
> /**
> * Dialog represent the Add Query configuration UI
> */
> @@ -55,19 +57,40 @@
> private String dialogHeadingPrefix;
> private Text queryIDText;
> private StyledText sqlStatementText;
> + private Text groupByElementText;
> + private Text rowNameText;
> + private Text rowNamespaceText;
> private PersistentDSContext dsContext;
> private WSO2DataserviceWizardStepTwo parentPage;
> private List configList;
> -
> + private List inputMapList;
> + private List outputMapList;
> + private boolean isEditMode=false;
> +
> public AddQueryDialog(Shell parentShell, String headingPrefix,
> WSO2DataserviceWizardStepTwo page) {
> super(parentShell);
> + configList = new ArrayList();
> + inputMapList=new ArrayList();
> + outputMapList=new ArrayList();
> + resetConfigData();
> dialogHeadingPrefix = headingPrefix;
> + isEditMode=headingPrefix.equals(WSO2DataserviceWizardConstant.editTag);
> //Obtain the current context from eclipse preferences.
> dsContext = WSO2DataservicePlugin.getDefault().getPersistentDSContext();
> parentPage = page;
> }
>
> + private void resetConfigData(){
> + configList.clear();
> + configList.add("");
> + configList.add("");
> + configList.add("");
> + configList.add("");
> + configList.add("");
> + configList.add(inputMapList);
> + configList.add(outputMapList);
> + }
> /**
> * Create the dialog area with the controls
> */
> @@ -189,7 +212,7 @@
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text groupByElementText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + groupByElementText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> groupByElementText.setLayoutData(gd);
> @@ -205,7 +228,7 @@
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text rowNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + rowNameText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> rowNameText.setLayoutData(gd);
> @@ -221,7 +244,7 @@
> gd.horizontalSpan = 1;
> label.setLayoutData(gd);
>
> - Text rowNamespaceText = new Text(container, SWT.BORDER | SWT.SINGLE);
> + rowNamespaceText = new Text(container, SWT.BORDER | SWT.SINGLE);
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> rowNamespaceText.setLayoutData(gd);
> @@ -252,10 +275,28 @@
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 3;
> label.setLayoutData(gd);
> -
> + /*
> + * setup the environment for edit mode
> + */
> + if (isEditMode){
> + String qId=parentPage.getSelectedQueryId();
> + List tmpConfigList=parentPage.getQueryData(qId);
> + resetQueryData(tmpConfigList);
> + configList=tmpConfigList;
> + queryIDText.setEditable(false);
> + }
> return super.createDialogArea(parent);
> }
>
> + private void resetQueryData(List tmpConfigList){
> + if (tmpConfigList!=null){
> + queryIDText.setText((String)tmpConfigList.get(0));
> + sqlStatementText.setText((String)tmpConfigList.get(1));
> + rowNamespaceText.setText((String)tmpConfigList.get(2));
> + groupByElementText.setText((String)tmpConfigList.get(3));
> + rowNameText.setText((String)tmpConfigList.get(4));
> + }
> + }
> /**
> * Handler method for the Output Mapping
> */
> @@ -265,6 +306,9 @@
> addOutputMappingDialog.create();
> addOutputMappingDialog.getShell().setSize(500, 350);
> addOutputMappingDialog.open();
> + if (addOutputMappingDialog.getReturnCode()==org.eclipse.jface.window.Window.OK){
> + outputMapList.add(addOutputMappingDialog.getMappingData());
> + }
> }
>
> /**
> @@ -276,6 +320,9 @@
> addInputParamDialog.create();
> addInputParamDialog.getShell().setSize(500, 350);
> addInputParamDialog.open();
> + if (addInputParamDialog.getReturnCode()==org.eclipse.jface.window.Window.OK){
> + inputMapList.add(addInputParamDialog.getMappingData());
> + }
> }
>
> /**
> @@ -290,33 +337,28 @@
> * Handle the OK button pressed
> */
> protected void okPressed() {
> - super.okPressed();
> - //Update the DS Configuration
> - configChanged();
> + if (isAllDataValid()){
> + super.okPressed();
> + //Update the DS Configuration
> + configChanged();
> + }
> }
>
> + private void showMsg(String msg){
> + MessageBox messageBox =new MessageBox(getShell(),SWT.OK);
> + messageBox.setMessage(msg);
> + messageBox.open();
> + }
> /**
> * Handle the configuration changes
> */
> private void configChanged(){
> //update config with the change
> try {
> - OMElement root = DataServiceXMLUtil.getOMDocFromString(dsContext.getDSConfig());
> - OMElement element = createQueryElement();
> - //Remove the existing data service config
> - Iterator children = root.getChildElements();
> - while(children.hasNext()){
> - OMElement node = (OMElement)children.next();
> - if (node.getLocalName().equals("query")) {
> - node.detach();
> - }
> - }
> - root.addChild(element);
> - OutputStream xmlOutputStream = new ByteArrayOutputStream();
> - root.serialize(xmlOutputStream);
> - //call refresh configuration
> - OutputStream stream = DataServiceXMLUtil.prettyPrintDSConfig(xmlOutputStream.toString());
> - parentPage.refreshConfig(stream.toString());
> + parentPage.setQueryData(
> + (String)configList.get(WSO2DataserviceWizardStepTwo.SQLQUERY_QUERYID).toString()
> + ,configList);
> + parentPage.configChanged();
> } catch (Exception e) {
> e.printStackTrace();
> }
> @@ -324,31 +366,15 @@
>
>
> /**
> - * Build the Query Element
> - * @param propertyList : List of properties of Data Service Connection Configuration.
> - * @return Query Element
> - */
> - public OMElement createQueryElement(){
> - //create a factory
> - OMFactory factory = OMAbstractFactory.getOMFactory();
> - //use the factory to create three elements
> - OMElement root = factory.createOMElement("query",null);
> - root.addAttribute("id",configList.get(0).toString(), null);
> -
> - OMElement currentElement = factory.createOMElement("sql",null);
> - currentElement.setText(configList.get(1).toString());
> - root.addChild(currentElement);
> - return root;
> - }
> -
> - /**
> * This method updates the List form current RDBMS Configuration.
> * @return RDBMS COnfiguration
> */
> private void createListFromQuerySConfig(){
> - configList = new ArrayList();
> - configList.add(queryIDText.getText());
> - configList.add(sqlStatementText.getText());
> + configList.set(WSO2DataserviceWizardStepTwo.SQLQUERY_QUERYID,queryIDText.getText());
> + configList.set(WSO2DataserviceWizardStepTwo.SQLQUERY_QUERY,sqlStatementText.getText());
> + configList.set(WSO2DataserviceWizardStepTwo.SQLQUERY_NAME_SPACE,rowNamespaceText.getText());
> + configList.set(WSO2DataserviceWizardStepTwo.SQLQUERY_ELEMENT,groupByElementText.getText());
> + configList.set(WSO2DataserviceWizardStepTwo.SQLQUERY_ROW_NAME,rowNameText.getText());
> }
>
> /**
> @@ -359,4 +385,36 @@
> return configList;
> }
>
> + private boolean isAllDataValid(){
> + if ((!isEditMode)&&(parentPage.getQueryData(configList.get(0).toString())!=null)){
> + showMsg("Query Id '"+configList.get(0).toString()+"' already present.");
> + return false;
> + }
> + if (configList.get(
> + WSO2DataserviceWizardStepTwo.SQLQUERY_QUERYID).toString().trim().equals("")){
> + showMsg("Query id is required.");
> + return false;
> + }
> +
> + if (configList.get(
> + WSO2DataserviceWizardStepTwo.SQLQUERY_QUERY).toString().trim().equals("")){
> + showMsg("Sql statement is required.");
> + return false;
> + }
> +
> + if (configList.get(
> + WSO2DataserviceWizardStepTwo.SQLQUERY_ELEMENT).toString().trim().equals("")){
> + showMsg("Group by element is required.");
> + return false;
> + }
> +
> + if (configList.get(
> + WSO2DataserviceWizardStepTwo.SQLQUERY_ROW_NAME).toString().trim().equals("")){
> + showMsg("Row name is required.");
> + return false;
> + }
> +
> +
> + return true;
> + }
> }
> \ No newline at end of file
>
> Modified: trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/wizard/WSO2DataserviceWizardStepTwo.java
> ==============================================================================
> --- trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/wizard/WSO2DataserviceWizardStepTwo.java (original)
> +++ trunk/solutions/data-services/java/modules/ide/src/org/wso2/ws/dataservice/ide/wizard/WSO2DataserviceWizardStepTwo.java Wed May 14 22:26:11 2008
> @@ -15,9 +15,15 @@
> */
> package org.wso2.ws.dataservice.ide.wizard;
>
> +import java.io.ByteArrayOutputStream;
> +import java.io.OutputStream;
> import java.util.ArrayList;
> +import java.util.Iterator;
> import java.util.List;
>
> +import org.apache.axiom.om.OMAbstractFactory;
> +import org.apache.axiom.om.OMElement;
> +import org.apache.axiom.om.OMFactory;
> import org.eclipse.jface.dialogs.IDialogPage;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.swt.SWT;
> @@ -29,9 +35,11 @@
> import org.eclipse.swt.widgets.Button;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Label;
> +import org.eclipse.swt.widgets.MessageBox;
> import org.eclipse.swt.widgets.Table;
> import org.eclipse.swt.widgets.TableColumn;
> import org.eclipse.swt.widgets.TableItem;
> +import org.eclipse.swt.widgets.Dialog;
> import org.wso2.ws.dataservice.ide.WSO2DataservicePlugin;
> import org.wso2.ws.dataservice.ide.constant.WSO2DataserviceWizardConstant;
> import org.wso2.ws.dataservice.ide.context.PersistentDSContext;
> @@ -52,6 +60,22 @@
> private Table table;
> private PersistentDSContext dsContext;
>
> + public static int SQLQUERY_QUERYID=0;
> + public static int SQLQUERY_QUERY=1;
> + public static int SQLQUERY_NAME_SPACE=2;
> + public static int SQLQUERY_ELEMENT=3;
> + public static int SQLQUERY_ROW_NAME=4;
> + public static int SQLQUERY_INPUT_MAPS=5;
> + public static int SQLQUERY_OUTPUT_MAPS=6;
> +
> + public static int SQLQUERY_IMAP_NAME=0;
> + public static int SQLQUERY_IMAP_SQL_TYPE=1;
> + public static int SQLQUERY_IMAP_INOUT_TYPE=2;
> + public static int SQLQUERY_IMAP_ORDINAL=3;
> +
> + public static int SQLQUERY_OMAP_TYPE=0;
> + public static int SQLQUERY_OMAP_OUT_FIELD=1;
> + public static int SQLQUERY_OMAP_SQL_COL=2;
> /**
> * Constructor for WSO2DataserviceWizardStepTwo.
> * @param pageName
> @@ -91,6 +115,11 @@
> gd.heightHint = 100;
> table.setLayoutData(gd);
> table.setVisible(false);
> + table.addSelectionListener(new SelectionAdapter(){
> + public void widgetSelected(SelectionEvent e) {
> + handleTableItemSelected();
> + }
> + });
>
> label = new Label(container, SWT.NULL);
> label.setText("");
> @@ -116,6 +145,8 @@
> handleEditQuery();
> }
> });
> + editButton.setEnabled(false);
> +
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> editButton.setLayoutData(gd);
> @@ -130,7 +161,8 @@
> gd = new GridData(GridData.FILL_HORIZONTAL);
> gd.horizontalSpan = 2;
> deleteButton.setLayoutData(gd);
> -
> + deleteButton.setEnabled(false);
> +
> label = new Label(container, SWT.NULL);
> label.setText("");
> gd = new GridData(GridData.FILL_HORIZONTAL);
> @@ -176,8 +208,13 @@
> private void updateTable(List fillItems) {
> if (fillItems != null) {
> int queryCount = fillItems.size();
> + table.removeAll();
> if (queryCount > 0) {
> - table.removeAll();
> + String selectedId=null;
> + int indexSelected=table.getSelectionIndex();
> + if (table.getSelectionIndex()>-1){
> + selectedId=table.getItem(table.getSelectionIndex()).getText();
> + }
> TableItem[] items = new TableItem[queryCount]; // An item for each field
> for (int i = 0; i < queryCount; i++) {
> items[i] = new TableItem(table, SWT.NONE);
> @@ -185,7 +222,17 @@
> List iQueryItem = (List)fillItems.get(i);
> items[i].setText(iQueryItem.get(0).toString());
> items[i].setChecked(true);//check them all by default
> + if (selectedId!=null){
> + if (iQueryItem.get(0).toString().equals(selectedId)){
> + indexSelected=i;
> + }
> + }
> +
> }
> + if (indexSelected>(queryCount-1)){
> + indexSelected=queryCount-1;
> + }
> + table.setSelection(indexSelected);
> updateStatus(null);
> }
> table.redraw();
> @@ -193,7 +240,67 @@
> table.setVisible(true);
> }
>
> -
> + /**
> + * Get the query information related to given query id
> + * @param queryId
> + * @return
> + */
> + public List getQueryData(String queryId){
> + int queryCount = queryToUIMapping.size();
> + for (int i = 0; i < queryCount; i++) {
> + List iQueryItem = (List)queryToUIMapping.get(i);
> + if (iQueryItem.get(SQLQUERY_QUERYID).toString().equals(queryId)){
> + return iQueryItem;
> + }
> + }
> + return null;
> + }
> +
> + public void setQueryData(String queryId, List data){
> + int queryCount = queryToUIMapping.size();
> + for (int i = 0; i < queryCount; i++) {
> + List iQueryItem = (List)queryToUIMapping.get(i);
> + if (iQueryItem.get(SQLQUERY_QUERYID).toString().equals(queryId)){
> + queryToUIMapping.set(i, data);
> + return;
> + }
> + }
> + queryToUIMapping.add(data);
> + }
> +
> + public void removeQueryData(String queryId){
> + int queryCount = queryToUIMapping.size();
> + for (int i = 0; i < queryCount; i++) {
> + List iQueryItem = (List)queryToUIMapping.get(i);
> + if (iQueryItem.get(SQLQUERY_QUERYID).toString().equals(queryId)){
> + queryToUIMapping.remove(i);
> + return;
> + }
> + }
> + }
> +
> +
> + public List getQueryIdList(){
> + List IdList=new ArrayList();
> + int queryCount = queryToUIMapping.size();
> + for (int i = 0; i < queryCount; i++) {
> + List iQueryItem = (List)queryToUIMapping.get(i);
> + IdList.add(iQueryItem.get(SQLQUERY_QUERYID).toString());
> + }
> + return IdList;
> + }
> +
> + /**
> + * return the query id of the selected item in the table
> + * @return
> + */
> + public String getSelectedQueryId(){
> + if (table.getSelectionIndex()>-1){
> + return table.getItem(table.getSelectionIndex()).getText();
> + }
> + return null;
> + }
> +
> private void declareColumn(Table table, int width,String colName){
> TableColumn column = new TableColumn(table,SWT.NONE);
> column.setWidth(width);
> @@ -209,6 +316,13 @@
> }
>
> /**
> + * Handle when an item in the query table is selected
> + */
> + private void handleTableItemSelected(){
> + editButton.setEnabled(table.getSelectionIndex()!=-1);
> + deleteButton.setEnabled(table.getSelectionIndex()!=-1);
> + }
> + /**
> * Handle add new Query
> */
> private void handleAddQuery() {
> @@ -218,10 +332,10 @@
> addQueryDialog.create();
> addQueryDialog.getShell().setSize(500, 700);
> addQueryDialog.open();
> -
> - noOfLoadedQuery++;
> - queryToUIMapping.add(addQueryDialog.getQueryList());
> - updateTable(queryToUIMapping);
> + if (addQueryDialog.getReturnCode()==org.eclipse.jface.window.Window.OK){
> + noOfLoadedQuery++;
> + updateTable(queryToUIMapping);
> + }
> }
>
> /**
> @@ -240,9 +354,12 @@
> * Handle delete Query
> */
> private void handleDeleteQuery() {
> - queryToUIMapping.remove("Test"+noOfLoadedQuery);
> + removeQueryData(getSelectedQueryId());
> + //queryToUIMapping.remove("Test"+noOfLoadedQuery);
> noOfLoadedQuery--;
> updateTable(queryToUIMapping);
> + configChanged();
> + handleTableItemSelected();
> }
>
> private void updateStatus(String message) {
> @@ -253,7 +370,8 @@
> public String loadPreviousConfig(){
> String defaultConfig = null;
> try {
> - defaultConfig = DataServiceXMLUtil.prettyPrintDSConfig(dsContext.getDSConfig()).toString();
> + defaultConfig =
> + DataServiceXMLUtil.prettyPrintDSConfig(dsContext.getDSConfig()).toString();
> refreshConfig(defaultConfig);
> } catch (Exception e) {
> e.printStackTrace();
> @@ -268,4 +386,86 @@
> dsContext.setDSConfig(config);
> }
>
> + /**
> + * Handle the configuration changes
> + */
> + public void configChanged(){
> + //update config with the change
> + try {
> + OMElement root = DataServiceXMLUtil.getOMDocFromString(dsContext.getDSConfig());
> + //Remove the existing data service config
> + Iterator children = root.getChildElements();
> + while(children.hasNext()){
> + OMElement node = (OMElement)children.next();
> + if (node.getLocalName().equals("query")) {
> + node.detach();
> + }
> + }
> + List qIdList=getQueryIdList();
> + OMElement element;
> + for(int i=0;i<qIdList.size();i++){
> + element = createQueryElement(getQueryData((String)qIdList.get(i)));
> + root.addChild(element);
> + }
> + OutputStream xmlOutputStream = new ByteArrayOutputStream();
> + root.serialize(xmlOutputStream);
> + //call refresh configuration
> + OutputStream stream =
> + DataServiceXMLUtil.prettyPrintDSConfig(xmlOutputStream.toString());
> + refreshConfig(stream.toString());
> + } catch (Exception e) {
> + e.printStackTrace();
> + }
> + }
> +
> + /**
> + * Build the Query Element
> + * @param propertyList : List of properties of Data Service Connection Configuration.
> + * @return Query Element
> + */
> + public OMElement createQueryElement(List configData){
> + //create a factory
> + OMFactory factory = OMAbstractFactory.getOMFactory();
> + //use the factory to create three elements
> + OMElement root = factory.createOMElement("query",null);
> + root.addAttribute("id",configData.get(SQLQUERY_QUERYID).toString(), null);
> +
> + OMElement currentElement = factory.createOMElement("sql",null);
> + currentElement.setText(configData.get(SQLQUERY_QUERY).toString());
> + root.addChild(currentElement);
> +
> + for(int i=0;i<((List)configData.get(SQLQUERY_INPUT_MAPS)).size();i++){
> + List mapData=(List)((List)configData.get(SQLQUERY_INPUT_MAPS)).get(i);
> + currentElement = factory.createOMElement("param",null);
> + currentElement.addAttribute(
> + "name",mapData.get(SQLQUERY_IMAP_NAME).toString(), null);
> + currentElement.addAttribute(
> + "sqlType",mapData.get(SQLQUERY_IMAP_SQL_TYPE).toString(), null);
> + currentElement.addAttribute(
> + "type",mapData.get(SQLQUERY_IMAP_INOUT_TYPE).toString(), null);
> + currentElement.addAttribute(
> + "ordinal",mapData.get(SQLQUERY_IMAP_ORDINAL).toString(), null);
> + root.addChild(currentElement);
> + }
> +
> + currentElement = factory.createOMElement("result",null);
> + currentElement.addAttribute("defaultNamespace",
> + configData.get(SQLQUERY_NAME_SPACE).toString(), null);
> + currentElement.addAttribute("element",configData.get(SQLQUERY_ELEMENT).toString(), null);
> + currentElement.addAttribute("rowName",configData.get(SQLQUERY_ROW_NAME).toString(), null);
> + for(int i=0;i<((List)configData.get(SQLQUERY_OUTPUT_MAPS)).size();i++){
> + List mapData=(List)((List)configData.get(SQLQUERY_OUTPUT_MAPS)).get(i);
> + OMElement tcurrentElement =
> + factory.createOMElement(
> + mapData.get(SQLQUERY_OMAP_TYPE).toString().toLowerCase(),null);
> + tcurrentElement.addAttribute(
> + "name",mapData.get(SQLQUERY_OMAP_OUT_FIELD).toString(), null);
> + tcurrentElement.addAttribute(
> + "column",mapData.get(SQLQUERY_OMAP_SQL_COL).toString(), null);
> + currentElement.addChild(tcurrentElement);
> + }
> + root.addChild(currentElement);
> + return root;
> + }
> +
> }
> \ No newline at end of file
>
> _______________________________________________
> Ds-java-dev mailing list
> Ds-java-dev at wso2.org
> http://wso2.org/cgi-bin/mailman/listinfo/ds-java-dev
>
>
--
Thanks
Lahiru Sandakith
http://www.wso2.org
GPG Key Fingerprint : 8CD8 68E0 4CBC 75CB 25BC 1AB1 FE5E 7464 1F01 9A0F
More information about the Ds-java-dev
mailing list