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;
025:
026: import java.io.BufferedWriter;
027: import java.io.FileWriter;
028: import java.io.IOException;
029: import java.io.PrintWriter;
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: import org.eclipse.core.resources.IFile;
034: import org.eclipse.core.resources.IProject;
035: import org.eclipse.core.resources.IResource;
036: import org.eclipse.core.resources.ResourcesPlugin;
037:
038: import com.bostechcorp.cbesb.common.util.project.ProjectInfoDocument;
039: import com.bostechcorp.cbesb.common.util.project.ProjectInfoParser;
040: import com.bostechcorp.cbesb.common.util.project.SubProjectBean;
041:
042: public class ProjectUtil {
043:
044: public static void refreshWorkplace() {
045: IProject[] projects = null;
046:
047: projects = ResourcesPlugin.getWorkspace().getRoot()
048: .getProjects();
049:
050: try {
051:
052: for (int i = 0; i < projects.length; i++) {
053: String projectname = projects[i].toString();
054:
055: projectname = projectname.substring(projectname
056: .indexOf("/"), projectname.length());
057:
058: // get resource
059: IResource myresource = ResourcesPlugin.getWorkspace()
060: .getRoot().findMember(projectname);
061:
062: // then just refresh it
063:
064: myresource.refreshLocal(IResource.DEPTH_INFINITE, null);
065:
066: }
067:
068: } catch (Exception e) {
069: e.printStackTrace();
070: }
071: }
072:
073: public static void refreshProject(String projectName) {
074:
075: try {
076:
077: IResource myresource = ResourcesPlugin.getWorkspace()
078: .getRoot().findMember(projectName);
079:
080: // then just refresh it
081:
082: myresource.refreshLocal(IResource.DEPTH_INFINITE, null);
083:
084: } catch (Exception e) {
085: e.printStackTrace();
086: }
087: }
088:
089: public static void writeFileComponentflow(String componentflow1,
090: String componentflow2, String projectName)
091: throws IOException {
092:
093: PrintWriter out1 = new PrintWriter(new BufferedWriter(
094: new FileWriter(componentflow1)));
095: out1.println("<?xml version=\"1.0\" encoding=\"ASCII\"?>");
096: out1
097: .println("<cfe:ComponentFlowEditorDocument xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:cfe=\"http://www.bostech.com/componentFlowEditor/1.1\"/>");
098: out1.close();
099:
100: PrintWriter out2 = new PrintWriter(new BufferedWriter(
101: new FileWriter(componentflow2)));
102: out2.println("<?xml version=\"1.0\" encoding=\"ASCII\"?>");
103:
104: out2
105: .println("<notation:Diagram xmi:version=\"2.0\" xmlns:xmi=\"http://www.omg.org/XMI\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:notation=\"http://www.eclipse.org/gmf/runtime/1.0.0/notation\" type=\"ComponentFlowEditor\">");
106: out2.println("<styles xsi:type=\"notation:DiagramStyle\"/>");
107: out2.println("<element href=\"" + projectName
108: + ".componentflow#/\"/>");
109: out2.println("</notation:Diagram>");
110: out2.close();
111: }
112:
113: public static List getRelatedProject(String selectProjectName) {
114:
115: List<IProject> browseProjects = new ArrayList();
116:
117: IProject selectProject = ResourcesPlugin.getWorkspace()
118: .getRoot().getProject(selectProjectName);
119: browseProjects.add(selectProject);
120: IFile supFile = selectProject.getFile("projectinfo.xml");
121: if (supFile.exists()) {
122: java.io.File infoFile = supFile.getLocation().toFile();
123: ProjectInfoDocument infoDoc = ProjectInfoParser
124: .load(infoFile);
125: for (SubProjectBean sub : infoDoc.getProject()
126: .getAllSubProjects()) {
127: if (!sub.getType().equals("JBI")) {
128: browseProjects.add(ResourcesPlugin.getWorkspace()
129: .getRoot().getProject(sub.getName()));
130: }
131: }
132: }
133: return browseProjects;
134: }
135: }
|