30 |
brianR |
1 |
/*
|
|
|
2 |
* Mylyn Connector for Serena Business Mashups
|
|
|
3 |
* Copyright 2010 Brian Rosenberger (Brutex Network)
|
|
|
4 |
*
|
|
|
5 |
* Licensed under the Apache License, Version 2.0 (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
|
|
|
8 |
*
|
|
|
9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
10 |
*
|
|
|
11 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
12 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
13 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
14 |
* See the License for the specific language governing permissions and
|
|
|
15 |
* limitations under the License.
|
|
|
16 |
*
|
|
|
17 |
* Serena, TeamTrack and Serena Business Mashup are
|
|
|
18 |
* registered trademarks of SERENA Software Inc.
|
|
|
19 |
*/
|
|
|
20 |
package net.brutex.mylyn.sbmconnector.ui;
|
|
|
21 |
|
39 |
brianR |
22 |
import java.awt.Color;
|
52 |
brianR |
23 |
import java.util.ArrayList;
|
39 |
brianR |
24 |
|
30 |
brianR |
25 |
import net.brutex.mylyn.sbmconnector.core.SBMRepositoryConnector;
|
39 |
brianR |
26 |
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
|
|
|
27 |
import net.brutex.mylyn.sbmconnector.core.model.SBMSystemFields;
|
52 |
brianR |
28 |
import net.brutex.sbm.wsclient.ReportInfo;
|
30 |
brianR |
29 |
|
|
|
30 |
import org.eclipse.jface.dialogs.Dialog;
|
|
|
31 |
import org.eclipse.jface.layout.GridDataFactory;
|
|
|
32 |
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
|
|
|
33 |
import org.eclipse.mylyn.tasks.core.TaskRepository;
|
|
|
34 |
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage;
|
|
|
35 |
import org.eclipse.swt.SWT;
|
39 |
brianR |
36 |
import org.eclipse.swt.events.SelectionEvent;
|
|
|
37 |
import org.eclipse.swt.events.SelectionListener;
|
30 |
brianR |
38 |
import org.eclipse.swt.layout.GridData;
|
|
|
39 |
import org.eclipse.swt.layout.GridLayout;
|
|
|
40 |
import org.eclipse.swt.widgets.Combo;
|
|
|
41 |
import org.eclipse.swt.widgets.Composite;
|
39 |
brianR |
42 |
import org.eclipse.swt.widgets.Display;
|
|
|
43 |
import org.eclipse.swt.widgets.Event;
|
30 |
brianR |
44 |
import org.eclipse.swt.widgets.Label;
|
39 |
brianR |
45 |
import org.eclipse.swt.widgets.List;
|
|
|
46 |
import org.eclipse.swt.widgets.Listener;
|
|
|
47 |
import org.eclipse.swt.widgets.Table;
|
|
|
48 |
import org.eclipse.swt.widgets.TableColumn;
|
|
|
49 |
import org.eclipse.swt.widgets.TableItem;
|
30 |
brianR |
50 |
import org.eclipse.swt.widgets.Text;
|
39 |
brianR |
51 |
import org.eclipse.swt.widgets.Widget;
|
52 |
brianR |
52 |
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
|
|
53 |
import org.eclipse.ui.forms.widgets.FormToolkit;
|
30 |
brianR |
54 |
|
|
|
55 |
public class SBMRepositoryQueryPage extends AbstractRepositoryQueryPage {
|
39 |
brianR |
56 |
|
30 |
brianR |
57 |
private Text sql_where_clause = null;
|
|
|
58 |
private Text query_title = null;
|
52 |
brianR |
59 |
private Combo reportcombo = null;
|
|
|
60 |
private ReportInfo selectedReport = null;
|
39 |
brianR |
61 |
|
52 |
brianR |
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 --";
|
|
|
66 |
|
30 |
brianR |
67 |
public SBMRepositoryQueryPage(String pageName, TaskRepository repository,
|
|
|
68 |
IRepositoryQuery query) {
|
|
|
69 |
super(pageName, repository, query);
|
|
|
70 |
setTitle("SBM Query");
|
|
|
71 |
setDescription("Please specify table database name.");
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
@Override
|
|
|
75 |
public void applyTo(IRepositoryQuery query) {
|
|
|
76 |
if (getQueryTitle() != null) {
|
|
|
77 |
query.setSummary(getQueryTitle());
|
|
|
78 |
}
|
52 |
brianR |
79 |
query.setAttribute(SQL_QUERY, sql_where_clause.getText());
|
|
|
80 |
query.setAttribute(SQL_QUERY_NAME, query_title.getText());
|
|
|
81 |
query.setAttribute(REPORT, selectedReport.getReportUUID());
|
30 |
brianR |
82 |
}
|
|
|
83 |
|
|
|
84 |
@Override
|
|
|
85 |
public String getQueryTitle() {
|
39 |
brianR |
86 |
if (query_title != null && !query_title.getText().isEmpty())
|
|
|
87 |
return query_title.getText();
|
30 |
brianR |
88 |
return "new query";
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
@Override
|
|
|
92 |
public void createControl(Composite arg0) {
|
39 |
brianR |
93 |
Composite control = new Composite(arg0, SWT.BORDER);
|
30 |
brianR |
94 |
control.setLayout(new GridLayout(2, false));
|
52 |
brianR |
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 |
|
30 |
brianR |
101 |
Label query_label = new Label(control, SWT.NONE);
|
|
|
102 |
query_label.setText("Query Name:");
|
52 |
brianR |
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 |
|
30 |
brianR |
162 |
query_title = new Text(control, SWT.BORDER);
|
39 |
brianR |
163 |
if (getQuery() != null)
|
|
|
164 |
query_title.setText(getQuery().getAttribute("name"));
|
30 |
brianR |
165 |
|
52 |
brianR |
166 |
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
|
39 |
brianR |
167 |
data.heightHint = 200;
|
52 |
brianR |
168 |
|
39 |
brianR |
169 |
Label label_sql = new Label(control, SWT.NONE);
|
|
|
170 |
label_sql.setText("SQL where:");
|
52 |
brianR |
171 |
sql_where_clause = new Text(control, SWT.MULTI | SWT.WRAP
|
|
|
172 |
| SWT.V_SCROLL | SWT.BORDER);
|
30 |
brianR |
173 |
GridData gd = new GridData(300, 150);
|
|
|
174 |
gd.horizontalSpan = 2;
|
|
|
175 |
sql_where_clause.setLayoutData(gd);
|
39 |
brianR |
176 |
if (getQuery() != null)
|
|
|
177 |
sql_where_clause.setText(getQuery().getAttribute("sql_where"));
|
|
|
178 |
|
52 |
brianR |
179 |
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.TOP)
|
|
|
180 |
.applyTo(query_title);
|
30 |
brianR |
181 |
Dialog.applyDialogFont(control);
|
|
|
182 |
setControl(control);
|
|
|
183 |
}
|
|
|
184 |
}
|