001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id:$
023: */
024: package com.bostechcorp.cbesb.ui.util.browser;
025:
026: import java.io.File;
027: import java.util.ArrayList;
028: import java.util.List;
029:
030: import org.eclipse.core.internal.resources.Project;
031: import org.eclipse.core.resources.IProject;
032: import org.eclipse.swt.SWT;
033: import org.eclipse.swt.widgets.Shell;
034: import org.eclipse.swt.widgets.TableItem;
035: import org.eclipse.swt.widgets.Text;
036: import org.eclipse.swt.widgets.Tree;
037: import org.eclipse.swt.widgets.TreeItem;
038: import org.eclipse.ui.plugin.AbstractUIPlugin;
039:
040: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
041: import com.bostechcorp.cbesb.ui.util.resource.ESBResourceManager;
042: import com.bostechcorp.cbesb.ui.util.ucm.GroovyCommenMethod;
043: import com.bostechcorp.cbesb.ui.util.ucm.UcmClassLoader;
044: import com.bostechcorp.cbesb.ui.util.ucm.UcmClassURLHelper;
045:
046: public class CustomCodeBrowseDialog extends BaseFileBrowser {
047:
048: private List list = null;
049:
050: private Object[] fileList = new Object[1];
051:
052: private String selectType = "";
053:
054: private String objectType = "";
055:
056: private Text textClass;
057:
058: private boolean flag = true;
059:
060: private String projectName;
061:
062: private String projectLocation;
063:
064: private CustomCodeBrowseDialog _this ;
065:
066: public String className = "";
067:
068: public CustomCodeBrowseDialog(AbstractUIPlugin plugin,
069: Shell parent, String title, List list, String selectType,
070: String objectType, Text textClass) {
071: super (parent, title);
072: this .list = list;
073: this .abstractUIPlugin = plugin;
074: this .selectType = selectType;
075: this .textClass = textClass;
076: this .objectType = objectType;
077: _this = this ;
078: }
079:
080: @Override
081: protected void okButtonListener() {
082: String name = fileTree.getSelection()[0].getText();
083: className = name;
084: if (objectType.equalsIgnoreCase("tcpip")) {
085: UcmClassLoader ucmClassLoader;
086: try {
087: ucmClassLoader = UcmClassLoader.getInstance(
088: UcmClassURLHelper.getURL(projectName,
089: projectLocation), _this .getClass()
090: .getClassLoader(), projectName,
091: projectLocation);
092: String description = ucmClassLoader
093: .getClassDescription(name);
094: //should release the sa url
095: UcmClassURLHelper.clearSaPath(projectName);
096: if (description != null && !description.equals("")) {
097: textClass.setText(description);
098: shell.dispose();
099: return;
100: }
101: } catch (Exception e1) {
102: textClass.setText(name);
103: shell.dispose();
104: e1.printStackTrace();
105: }
106: }
107: if (selectType.equalsIgnoreCase("groovy")) {
108: String selectProject = folderTree.getSelection()[0]
109: .getParentItem().getParentItem().getText();
110: String saName = ((Project) list.get(0)).getName();
111: if (!selectProject.equals(saName)) {
112: selectProject = saName + "::" + selectProject;
113: }
114: textClass.setText(MacroUtil.changeToMacroPath(selectProject
115: + "::src/script/" + name, saName));
116: } else
117: textClass.setText(name);
118: shell.dispose();
119:
120: }
121:
122: @Override
123: protected void fileTreeListenser() {
124: if (fileTree.getSelection() != null
125: && fileTree.getSelection().length > 0) {
126: if (fileTree.getSelection()[0] != null) {
127: okButton.setEnabled(true);
128: }
129: }
130: }
131:
132: @Override
133: public void folderTreeListenser() {
134: okButton.setEnabled(false);
135: folderTreeSelected(folderTree.getSelection());
136:
137: }
138:
139: public void checkTreeTable() {
140: if (list != null) {
141: for (int i = 0; i < list.size(); i++) {
142: IProject project = (IProject) list.get(i);
143: TreeItem rootItem = new TreeItem(folderTree, SWT.None);
144: rootItem.setText(project.getName());
145: rootItem.setData(project.getLocation().toFile());
146: rootItem.setImage(ESBResourceManager.getPluginImage(
147: abstractUIPlugin, "icons/dialog/FOLDER.GIF"));
148: loopFolder(project.getLocation().toFile(), rootItem);
149: expandNode();
150: }
151: cleanFolder(folderTree);
152: folderTreeSelected(folderTree.getSelection());
153: }
154: }
155:
156: public void expandNode() {
157: Tree tree = folderTree;
158: for (int k = 0; k < tree.getItemCount(); k++) {
159: TreeItem rootItem = tree.getItem(k);
160: rootItem.setExpanded(true);
161: for (int i = 0; i < rootItem.getItemCount(); i++) {
162: rootItem.getItem(i).setExpanded(true);
163:
164: if (selectType.equals("Groovy")) {
165: if (rootItem.getItem(i).getText().equals("src")) {
166: for (int j = 0; j < rootItem.getItem(i)
167: .getItemCount(); j++) {
168: if (rootItem.getItem(i).getItem(j)
169: .getText().equals("script")) {
170: if (flag) {
171: tree.setSelection(rootItem.getItem(
172: i).getItem(j));
173: flag = false;
174: }
175: } else {
176: rootItem.getItem(i).getItem(j)
177: .dispose();
178: j--;
179: }
180: }
181: } else {
182: rootItem.getItem(i).dispose();
183: i--;
184: }
185: } else if (selectType.equalsIgnoreCase("java")) {
186: if (rootItem.getItem(i).getText().equals("lib")) {
187: for (TreeItem item : rootItem.getItem(i)
188: .getItems()) {
189: item.dispose();
190: }
191: } else {
192: rootItem.getItem(i).dispose();
193: i--;
194: }
195: }
196:
197: }
198: }
199: }
200:
201: /**
202: * clean the tree which has invalid items ,such as .svn
203: *
204: * @param tree
205: */
206: public void cleanFolder(Tree tree) {
207: for (TreeItem item : tree.getItems()) {
208: if (item.getText().startsWith(".")) {
209: item.dispose();
210: continue;
211: }
212: if (item.getItems().length != 0) {
213: cleanFolder(item);
214: }
215: }
216: }
217:
218: /**
219: * clean the rootItem which has invalid items ,such as .svn
220: *
221: * @param rootItem
222: */
223: public void cleanFolder(TreeItem rootItem) {
224: for (TreeItem item : rootItem.getItems()) {
225: if (item.getText().startsWith(".")) {
226: item.dispose();
227: continue;
228: }
229: if (item.getItems().length != 0) {
230: cleanFolder(item);
231: }
232: }
233: }
234:
235: public void loopFolder(File file, TreeItem rootItem) {
236: for (File subFile : file.getAbsoluteFile().listFiles()) {
237: TreeItem item = null;
238: if (subFile.isDirectory()) {
239: item = new TreeItem(rootItem, SWT.NONE);
240: item.setText(subFile.getName());
241: item.setData(subFile);
242: item.setImage(ESBResourceManager.getPluginImage(
243: abstractUIPlugin, "icons/dialog/FOLDER.GIF"));
244: }
245: if (subFile.listFiles() != null) {
246: loopFolder(subFile, item);
247: }
248: }
249: }
250:
251: private void folderTreeSelected(TreeItem[] treeItems) {
252: if (treeItems != null && treeItems.length > 0
253: && selectType.equalsIgnoreCase("groovy")
254: && treeItems[0].getText().equalsIgnoreCase("script")) {
255: for (TableItem item : fileTree.getItems()) {
256: item.dispose();
257: }
258: fileTree.layout();
259: List<String> list = new ArrayList<String>();
260: GroovyCommenMethod.getInstance().getGroovyClass(
261: (File) treeItems[0].getData(), list);
262: if (list.size() != 0) {
263: for (int i = 0; i < list.size(); i++) {
264: TableItem subItem = new TableItem(fileTree,
265: SWT.NONE);
266: subItem.setText(list.get(i));
267: subItem.setImage(ESBResourceManager
268: .getPluginImage(abstractUIPlugin,
269: "icons/dialog/sample.gif"));
270: }
271: }
272: } else if (treeItems != null && treeItems.length > 0
273: && selectType.equalsIgnoreCase("java")
274: && treeItems[0].getText().equalsIgnoreCase("lib")) {
275: for (TableItem item : fileTree.getItems()) {
276: item.dispose();
277: }
278: fileTree.layout();
279: List tempList = null;
280: String currentFile = ((File) treeItems[0].getData())
281: .getPath();
282: Project project = (Project) list.get(0);
283: int length = project.getLocation().toOSString()
284: .lastIndexOf(File.separator);
285: String temp = currentFile.substring(length + 1, currentFile
286: .length());
287: projectName = temp.substring(0, temp
288: .indexOf(File.separator));
289: projectLocation = project.getLocation().toOSString()
290: .substring(0, length + 1)
291: + projectName;
292: treeItems[0].getData();
293: UcmClassLoader ucmClassLoader;
294: try {
295: ucmClassLoader = UcmClassLoader.getInstance(
296: UcmClassURLHelper.getURL(projectName,
297: projectLocation), this .getClass()
298: .getClassLoader(), projectName,
299: projectLocation);
300: if (objectType.equalsIgnoreCase("script"))
301: tempList = ucmClassLoader.getScriptClassList();
302: else if (objectType.equalsIgnoreCase("trxID"))
303: tempList = ucmClassLoader.getTrxIDClassList();
304: else if (objectType.equalsIgnoreCase("mapFilter"))
305: tempList = ucmClassLoader.getMapFilterClassList();
306: else if (objectType.equalsIgnoreCase("mapUserOper"))
307: tempList = ucmClassLoader.getMapUserOperClassList();
308: else if (objectType.equalsIgnoreCase("upoc"))
309: tempList = ucmClassLoader.getUpocClassList();
310: else if (objectType.equalsIgnoreCase("tcpip"))
311: tempList = ucmClassLoader.getTcpIpHandleClassList();
312: else if (objectType.equalsIgnoreCase("errorHandler"))
313: tempList = ucmClassLoader
314: .getEtlErrorHandlerClassList();
315:
316: } catch (Exception e1) {
317:
318: e1.printStackTrace();
319: }
320:
321: if (tempList.size() != 0) {
322: for (int i = 0; i < tempList.size(); i++) {
323: TableItem subItem = new TableItem(fileTree,
324: SWT.NONE);
325: subItem.setText(tempList.get(i).toString());
326: subItem.setImage(ESBResourceManager
327: .getPluginImage(abstractUIPlugin,
328: "icons/dialog/sample.gif"));
329: }
330: }
331: //should release the sa url
332: UcmClassURLHelper.clearSaPath(projectName);
333:
334: }
335: }
336:
337: public void setFileImage(TableItem item) {
338:
339: }
340:
341: public Object[] getResult() {
342: return fileList;
343: }
344:
345: public void expandTreeNode(TreeItem item) {
346: if (item.getItemCount() > 0) {
347: item.setExpanded(true);
348: for (int i = 0; i < item.getItemCount(); i++) {
349: TreeItem subItem = item.getItem(i);
350: if (subItem.getText().equals("segments")) {
351: subItem.dispose();
352: i--;
353: } else {
354: expandTreeNode(subItem);
355: }
356: }
357: }
358: }
359:
360: public String getClassName() {
361: return className;
362: }
363: }
|