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.ide.wizards;
025:
026: import java.io.File;
027: import java.io.FileOutputStream;
028: import java.io.IOException;
029: import java.io.OutputStream;
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.ResourcesPlugin;
036: import org.eclipse.core.runtime.CoreException;
037: import org.eclipse.jdt.core.JavaModelException;
038: import org.eclipse.jface.viewers.CheckboxTableViewer;
039: import org.eclipse.jface.wizard.WizardPage;
040: import org.eclipse.swt.SWT;
041: import org.eclipse.swt.events.SelectionAdapter;
042: import org.eclipse.swt.events.SelectionEvent;
043: import org.eclipse.swt.layout.FormAttachment;
044: import org.eclipse.swt.layout.FormData;
045: import org.eclipse.swt.layout.FormLayout;
046: import org.eclipse.swt.widgets.Composite;
047: import org.eclipse.swt.widgets.Label;
048: import org.eclipse.swt.widgets.Table;
049: import org.eclipse.swt.widgets.TableItem;
050:
051: import com.bostechcorp.cbesb.common.i18n.I18N;
052: import com.bostechcorp.cbesb.common.i18n.Messages;
053: import com.bostechcorp.cbesb.common.util.project.ProjectInfoDocument;
054: import com.bostechcorp.cbesb.common.util.project.ProjectInfoParser;
055:
056: /**
057: *
058: */
059: public class JBISAProjectCreationWizardSecondPage extends WizardPage {
060:
061: private JBISAProjectCreationWizardPage firstPage;
062:
063: private List selectedProjects = new ArrayList();
064:
065: private Table table;
066:
067: protected JBISAProjectCreationWizardSecondPage(String pageName,
068: JBISAProjectCreationWizardPage firstPage) {
069: super (pageName);
070: this .firstPage = firstPage;
071:
072: }
073:
074: public void createJBIProjectInfoFile(IProject project)
075: throws CoreException, JavaModelException, IOException {
076: String buildFilePath = project.getProject().getLocation()
077: .append("/projectinfo.xml").toOSString();
078: File buildFile = new File(buildFilePath);
079: if (!buildFile.exists())
080: return;
081: ProjectInfoDocument document = ProjectInfoParser
082: .load(buildFile);
083: if (document.getProject().getType().toUpperCase().equals("ESB"))
084: return;
085: if (selectedProjects != null) {
086: for (int i = 0; i < selectedProjects.size(); i++) {
087: ProjectInfoDocument doc = null;
088: File infoFile = null;
089: IProject supProject = ResourcesPlugin.getWorkspace()
090: .getRoot().getProject(
091: selectedProjects.get(i).toString());
092: IFile file = supProject.getFile("projectinfo.xml");
093: if (file.exists()) {
094: infoFile = file.getLocation().toFile();
095: doc = ProjectInfoParser.load(infoFile);
096: doc.getProject().addNewSubProject(
097: project.getName(), "JBI");
098: document.getProject().addNewSubProject(
099: supProject.getName(), "ESB");
100: }
101: OutputStream out = new FileOutputStream(infoFile);
102: doc.serialize(out);
103: out.close();
104: }
105:
106: }
107: OutputStream out = new FileOutputStream(buildFile);
108: document.serialize(out);
109: // project.refreshLocal(2, new SubProgressMonitor(monitor, 1));
110:
111: }
112:
113: public void createControl(Composite parent) {
114: // BuildPathAdapter adapter= new BuildPathAdapter();
115: // String[] buttonLabels= new String[] {
116: // NewWizardMessages.BuildPathsBlock_classpath_up_button,
117: // NewWizardMessages.BuildPathsBlock_classpath_down_button,
118: // /* 2 */ null,
119: // NewWizardMessages.BuildPathsBlock_classpath_checkall_button,
120: // NewWizardMessages.BuildPathsBlock_classpath_uncheckall_button
121: //
122: // };
123: // fBuildPathDialogField= new StringButtonDialogField(adapter);
124: // fBuildPathDialogField.setButtonLabel(NewWizardMessages.BuildPathsBlock_buildpath_button);
125: // fBuildPathDialogField.setDialogFieldListener(adapter);
126: // fBuildPathDialogField.setLabelText(NewWizardMessages.BuildPathsBlock_buildpath_label);
127: //
128: // //
129: // fClassPathList= new CheckedListDialogField(null, buttonLabels, new
130: // CPListLabelProvider());
131: // fClassPathList.setDialogFieldListener(adapter);
132: // fClassPathList.setLabelText(NewWizardMessages.BuildPathsBlock_classpath_label);
133: // fClassPathList.setUpButtonIndex(0);
134: // fClassPathList.setDownButtonIndex(1);
135: // fClassPathList.setCheckAllButtonIndex(3);
136: // fClassPathList.setUncheckAllButtonIndex(4);
137: //
138:
139: //
140: Composite composite = new Composite(parent, SWT.NONE);
141: composite.setLayout(new FormLayout());
142:
143: //
144: setControl(composite);
145:
146: final CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer
147: .newCheckList(composite, SWT.BORDER);
148: table = checkboxTableViewer.getTable();
149: table.addSelectionListener(new SelectionAdapter() {
150: public void widgetSelected(final SelectionEvent e) {
151: selectedProjects.clear();
152: for (int i = 0; i < table.getItemCount(); i++) {
153: if (table.getItem(i).getChecked()) {
154: selectedProjects
155: .add(table.getItem(i).getText());
156: setPageComplete(true);
157: // getContainer().updateButtons();
158: } else {
159: setPageComplete(false);
160: }
161: }
162: ((JBISAProjectCreationWizardPage) firstPage)
163: .setSuperProjects(selectedProjects);
164:
165: }
166: });
167: final FormData formData_1 = new FormData();
168: formData_1.bottom = new FormAttachment(100, -5);
169: formData_1.right = new FormAttachment(100, -5);
170: formData_1.top = new FormAttachment(0, 26);
171: formData_1.left = new FormAttachment(0, 5);
172: table.setLayoutData(formData_1);
173:
174: final Label addReferenceLabel = new Label(composite, SWT.NONE);
175: final FormData formData = new FormData();
176: formData.right = new FormAttachment(0, 120);
177: formData.bottom = new FormAttachment(table, -5, SWT.TOP);
178: formData.top = new FormAttachment(0, 5);
179: formData.left = new FormAttachment(table, 0, SWT.LEFT);
180: addReferenceLabel.setLayoutData(formData);
181: addReferenceLabel.setText(I18N.getString(Messages.IDE_ADD_REF));
182:
183: IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
184: .getProjects();
185: for (IProject project : projects) {
186: IFile file = project.getFile("projectinfo.xml");
187: if (file.exists()) {
188: File infoFile = file.getLocation().toFile();
189: ProjectInfoDocument infoDoc = ProjectInfoParser
190: .load(infoFile);
191: if (infoDoc.getProject().getType().equals("ESB")) {
192: TableItem item = new TableItem(table, SWT.NONE);
193: item.setText(infoDoc.getProject().getName());
194: }
195: }
196:
197: }
198:
199: // checkboxTableViewer.setInput(new Object());
200: }
201:
202: // private class BuildPathAdapter implements IStringButtonAdapter,
203: // IDialogFieldListener {
204: //
205: // // -------- IStringButtonAdapter --------
206: // public void changeControlPressed(DialogField field) {
207: // buildPathChangeControlPressed(field);
208: // }
209: //
210: // // ---------- IDialogFieldListener --------
211: // public void dialogFieldChanged(DialogField field) {
212: // buildPathDialogFieldChanged(field);
213: // }
214: //
215: // private void buildPathChangeControlPressed(DialogField field) {
216: // if (field == fBuildPathDialogField) {
217: // IContainer container= chooseContainer();
218: // if (container != null) {
219: // fBuildPathDialogField.setText(container.getFullPath().toString());
220: // }
221: // }
222: // }
223: //
224: // private void buildPathDialogFieldChanged(DialogField field) {
225: // if (field == fClassPathList) {
226: // //updateClassPathStatus();
227: // } else if (field == fBuildPathDialogField) {
228: // //updateOutputLocationStatus();
229: // }
230: // //doStatusLineUpdate();
231: // }
232: //
233: // private IContainer chooseContainer() {
234: // Class[] acceptedClasses= new Class[] { IProject.class, IFolder.class };
235: // ISelectionStatusValidator validator= new
236: // TypedElementSelectionValidator(acceptedClasses, false);
237: // IProject[] allProjects=
238: // ResourcesPlugin.getWorkspace().getRoot().getProjects();
239: // ArrayList rejectedElements= new ArrayList(allProjects.length);
240: // IProject currProject= firstPage.fCurrJProject.getProject();
241: // for (int i= 0; i < allProjects.length; i++) {
242: // if (!allProjects[i].equals(currProject)) {
243: // rejectedElements.add(allProjects[i]);
244: // }
245: // }
246: // ViewerFilter filter= new TypedViewerFilter(acceptedClasses,
247: // rejectedElements.toArray());
248: //
249: // ILabelProvider lp= new WorkbenchLabelProvider();
250: // ITreeContentProvider cp= new WorkbenchContentProvider();
251: //
252: // IResource initSelection= null;
253: // if (fOutputLocationPath != null) {
254: // initSelection= fWorkspaceRoot.findMember(fOutputLocationPath);
255: // }
256: //
257: // FolderSelectionDialog dialog= new FolderSelectionDialog(getShell(), lp,
258: // cp);
259: // dialog.setTitle(NewWizardMessages.BuildPathsBlock_ChooseOutputFolderDialog_title);
260: // dialog.setValidator(validator);
261: // dialog.setMessage(NewWizardMessages.BuildPathsBlock_ChooseOutputFolderDialog_description);
262: // dialog.addFilter(filter);
263: // dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
264: // dialog.setInitialSelection(initSelection);
265: // dialog.setSorter(new ResourceSorter(ResourceSorter.NAME));
266: //
267: // if (dialog.open() == Window.OK) {
268: // return (IContainer)dialog.getFirstResult();
269: // }
270: // return null;
271: // }
272: //
273: //
274: // }
275:
276: public boolean isPageComplete() {
277: for (int i = 0; i < table.getItemCount(); i++) {
278: if (table.getItem(i).getChecked()) {
279: return true;
280: }
281: }
282: return false;
283: }
284:
285: // @Override
286: // public void setPageComplete(boolean complete) {
287: //
288: // super.setPageComplete(complete);
289: // }
290: }
|