Subversion Repositories XServices

Rev

Rev 39 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 39 Rev 52
1
/*
1
/*
2
 *   Mylyn Connector for Serena Business Mashups
2
 *   Mylyn Connector for Serena Business Mashups
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
4
 *
4
 *
5
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   Licensed under the Apache License, Version 2.0 (the "License");
6
 *   you may not use this file except in compliance with the License.
6
 *   you may not use this file except in compliance with the License.
7
 *   You may obtain a copy of the License at
7
 *   You may obtain a copy of the License at
8
 *
8
 *
9
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *       http://www.apache.org/licenses/LICENSE-2.0
10
 *
10
 *
11
 *   Unless required by applicable law or agreed to in writing, software
11
 *   Unless required by applicable law or agreed to in writing, software
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *   See the License for the specific language governing permissions and
14
 *   See the License for the specific language governing permissions and
15
 *   limitations under the License.
15
 *   limitations under the License.
16
 * 
16
 * 
17
 *   Serena, TeamTrack and Serena Business Mashup are 
17
 *   Serena, TeamTrack and Serena Business Mashup are 
18
 * 	 registered trademarks of SERENA Software Inc.
18
 * 	 registered trademarks of SERENA Software Inc.
19
 */
19
 */
20
package net.brutex.mylyn.sbmconnector.ui;
20
package net.brutex.mylyn.sbmconnector.ui;
21
 
21
 
22
import java.awt.Color;
22
import java.awt.Color;
-
 
23
import java.util.ArrayList;
23
 
24
 
24
import net.brutex.mylyn.sbmconnector.core.SBMRepositoryConnector;
25
import net.brutex.mylyn.sbmconnector.core.SBMRepositoryConnector;
25
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
26
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
26
import net.brutex.mylyn.sbmconnector.core.model.SBMSystemFields;
27
import net.brutex.mylyn.sbmconnector.core.model.SBMSystemFields;
-
 
28
import net.brutex.sbm.wsclient.ReportInfo;
27
 
29
 
28
import org.eclipse.jface.dialogs.Dialog;
30
import org.eclipse.jface.dialogs.Dialog;
29
import org.eclipse.jface.layout.GridDataFactory;
31
import org.eclipse.jface.layout.GridDataFactory;
30
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
32
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
31
import org.eclipse.mylyn.tasks.core.TaskRepository;
33
import org.eclipse.mylyn.tasks.core.TaskRepository;
32
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage;
34
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage;
33
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.events.SelectionListener;
37
import org.eclipse.swt.events.SelectionListener;
36
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
39
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Combo;
39
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Display;
42
import org.eclipse.swt.widgets.Display;
41
import org.eclipse.swt.widgets.Event;
43
import org.eclipse.swt.widgets.Event;
42
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Label;
43
import org.eclipse.swt.widgets.List;
45
import org.eclipse.swt.widgets.List;
44
import org.eclipse.swt.widgets.Listener;
46
import org.eclipse.swt.widgets.Listener;
45
import org.eclipse.swt.widgets.Table;
47
import org.eclipse.swt.widgets.Table;
46
import org.eclipse.swt.widgets.TableColumn;
48
import org.eclipse.swt.widgets.TableColumn;
47
import org.eclipse.swt.widgets.TableItem;
49
import org.eclipse.swt.widgets.TableItem;
48
import org.eclipse.swt.widgets.Text;
50
import org.eclipse.swt.widgets.Text;
49
import org.eclipse.swt.widgets.Widget;
51
import org.eclipse.swt.widgets.Widget;
-
 
52
import org.eclipse.ui.forms.widgets.ExpandableComposite;
-
 
53
import org.eclipse.ui.forms.widgets.FormToolkit;
50
 
54
 
51
public class SBMRepositoryQueryPage extends AbstractRepositoryQueryPage {
55
public class SBMRepositoryQueryPage extends AbstractRepositoryQueryPage {
52
 
56
 
53
	private Text sql_where_clause = null;
57
	private Text sql_where_clause = null;
54
	private Text query_title = null;
58
	private Text query_title = null;
-
 
59
	private Combo reportcombo = null;
-
 
60
	private ReportInfo selectedReport = null;
-
 
61
 
-
 
62
	public static String SQL_QUERY = "sql_where";
-
 
63
	public static String SQL_QUERY_NAME = "name";
-
 
64
	public static String REPORT = "report";
-
 
65
	public static String REPORT_OR_QUERY = "-- use query --";
55
 
66
 
56
	public SBMRepositoryQueryPage(String pageName, TaskRepository repository,
67
	public SBMRepositoryQueryPage(String pageName, TaskRepository repository,
57
			IRepositoryQuery query) {
68
			IRepositoryQuery query) {
58
		super(pageName, repository, query);
69
		super(pageName, repository, query);
59
		setTitle("SBM Query");
70
		setTitle("SBM Query");
60
		setDescription("Please specify table database name.");
71
		setDescription("Please specify table database name.");
61
	}
72
	}
62
 
73
 
63
	@Override
74
	@Override
64
	public void applyTo(IRepositoryQuery query) {
75
	public void applyTo(IRepositoryQuery query) {
65
		if (getQueryTitle() != null) {
76
		if (getQueryTitle() != null) {
66
			query.setSummary(getQueryTitle());
77
			query.setSummary(getQueryTitle());
67
		}
78
		}
68
		query.setAttribute("sql_where", sql_where_clause.getText());
79
		query.setAttribute(SQL_QUERY, sql_where_clause.getText());
69
		query.setAttribute("name", query_title.getText());
80
		query.setAttribute(SQL_QUERY_NAME, query_title.getText());
-
 
81
		query.setAttribute(REPORT, selectedReport.getReportUUID());
70
	}
82
	}
71
 
83
 
72
	@Override
84
	@Override
73
	public String getQueryTitle() {
85
	public String getQueryTitle() {
74
		if (query_title != null && !query_title.getText().isEmpty())
86
		if (query_title != null && !query_title.getText().isEmpty())
75
			return query_title.getText();
87
			return query_title.getText();
76
		return "new query";
88
		return "new query";
77
	}
89
	}
78
 
90
 
79
	@Override
91
	@Override
80
	public void createControl(Composite arg0) {
92
	public void createControl(Composite arg0) {
81
		Composite control = new Composite(arg0, SWT.BORDER);
93
		Composite control = new Composite(arg0, SWT.BORDER);
82
		control.setLayout(new GridLayout(2, false));
94
		control.setLayout(new GridLayout(2, false));
-
 
95
 
-
 
96
		Label report_label = new Label(control, SWT.NONE);
-
 
97
		reportcombo = new Combo(control, SWT.SINGLE | SWT.BORDER);
-
 
98
		new Label(control, SWT.NONE).setText(" OR ");
-
 
99
		new Label(control, SWT.SEPARATOR | SWT.HORIZONTAL);
-
 
100
 
83
		Label query_label = new Label(control, SWT.NONE);
101
		Label query_label = new Label(control, SWT.NONE);
84
		query_label.setText("Query Name:");
102
		query_label.setText("Query Name:");
-
 
103
 
-
 
104
		report_label.setText("Report");
-
 
105
 
-
 
106
		String solutionname = getTaskRepository().getProperty(
-
 
107
				SBMRepositorySettingsPage.STRING_SOLUTIONTABLE);
-
 
108
 
-
 
109
		try {
-
 
110
			final java.util.List<ReportInfo> reportlist = SBMRepositoryConnector
-
 
111
					.getClient(getTaskRepository()).getReportList(solutionname);
-
 
112
 
-
 
113
			reportcombo.add(REPORT_OR_QUERY);
-
 
114
			reportcombo.select(0);
-
 
115
			for (ReportInfo report : reportlist) {
-
 
116
				reportcombo.add(report.getReportName());
-
 
117
			}
-
 
118
 
-
 
119
			reportcombo.addListener(SWT.Selection, new Listener() {
-
 
120
 
-
 
121
				@Override
-
 
122
				public void handleEvent(Event arg0) {
-
 
123
					if (reportcombo.getSelectionIndex() == 0) {
-
 
124
						query_title.setEditable(true);
-
 
125
						query_title.setEnabled(true);
-
 
126
						sql_where_clause.setEditable(true);
-
 
127
						sql_where_clause.setEnabled(true);
-
 
128
						query_title.setText("");
-
 
129
					} else {
-
 
130
						query_title.setEditable(false);
-
 
131
						query_title.setEnabled(false);
-
 
132
						sql_where_clause.setEditable(false);
-
 
133
						sql_where_clause.setEnabled(false);
-
 
134
						query_title.setText(reportcombo.getText());
-
 
135
						selectedReport = reportlist.get(reportcombo
-
 
136
								.getSelectionIndex() - 1);
-
 
137
 
-
 
138
					}
-
 
139
 
-
 
140
				}
-
 
141
			});
-
 
142
 
-
 
143
		} catch (Exception e) {
-
 
144
		}
-
 
145
		/*
-
 
146
		 * 
-
 
147
		 * 
-
 
148
		 * table.addListener(SWT.Selection, new Listener() {
-
 
149
		 * 
-
 
150
		 * @Override public void handleEvent(Event arg0) { // when the table has
-
 
151
		 * been changed // try to re-read the field list tableFieldList = "";
-
 
152
		 * tableFullFieldList = ""; try { SBMField[] fields =
-
 
153
		 * SBMRepositoryConnector.getClient(
-
 
154
		 * createTaskRepository()).getFields(table.getText()) .toArray(new
-
 
155
		 * SBMField[0]); fillList(list, fields); } catch (Exception e) { } if
-
 
156
		 * (getWizard() != null) { solutionTable = table.getText();
-
 
157
		 * getWizard().getContainer().updateButtons(); } }
-
 
158
		 * 
-
 
159
		 * }); regenerateTables(); expander.setClient(control);
-
 
160
		 */
-
 
161
 
85
		query_title = new Text(control, SWT.BORDER);
162
		query_title = new Text(control, SWT.BORDER);
86
		if (getQuery() != null)
163
		if (getQuery() != null)
87
			query_title.setText(getQuery().getAttribute("name"));
164
			query_title.setText(getQuery().getAttribute("name"));
88
 
165
 
89
				GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
166
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
90
		data.heightHint = 200;
167
		data.heightHint = 200;
91
		
168
 
92
		Label label_sql = new Label(control, SWT.NONE);
169
		Label label_sql = new Label(control, SWT.NONE);
93
		label_sql.setText("SQL where:");
170
		label_sql.setText("SQL where:");
-
 
171
		sql_where_clause = new Text(control, SWT.MULTI | SWT.WRAP
94
		sql_where_clause = new Text(control, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
172
				| SWT.V_SCROLL | SWT.BORDER);
95
		GridData gd = new GridData(300, 150);
173
		GridData gd = new GridData(300, 150);
96
		gd.horizontalSpan = 2;
174
		gd.horizontalSpan = 2;
97
		sql_where_clause.setLayoutData(gd);
175
		sql_where_clause.setLayoutData(gd);
98
		if (getQuery() != null)
176
		if (getQuery() != null)
99
			sql_where_clause.setText(getQuery().getAttribute("sql_where"));
177
			sql_where_clause.setText(getQuery().getAttribute("sql_where"));
100
 
178
 
101
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP).applyTo(
179
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP)
102
				query_title);
180
				.applyTo(query_title);
103
		Dialog.applyDialogFont(control);
181
		Dialog.applyDialogFont(control);
104
		setControl(control);
182
		setControl(control);
105
	}
183
	}
106
}
184
}