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.editor;
025:
026: import java.io.InputStream;
027: import java.util.ArrayList;
028:
029: import org.eclipse.jface.resource.ImageDescriptor;
030: import org.eclipse.jface.wizard.WizardPage;
031: import org.eclipse.swt.SWT;
032: import org.eclipse.swt.events.SelectionAdapter;
033: import org.eclipse.swt.events.SelectionEvent;
034: import org.eclipse.swt.layout.FillLayout;
035: import org.eclipse.swt.layout.GridData;
036: import org.eclipse.swt.layout.GridLayout;
037: import org.eclipse.swt.widgets.Button;
038: import org.eclipse.swt.widgets.Combo;
039: import org.eclipse.swt.widgets.Composite;
040: import org.eclipse.swt.widgets.Event;
041: import org.eclipse.swt.widgets.FileDialog;
042: import org.eclipse.swt.widgets.Group;
043: import org.eclipse.swt.widgets.Text;
044: import org.eclipse.ui.IWorkbench;
045: import org.eclipse.ui.IWorkbenchPage;
046: import org.eclipse.ui.IWorkbenchWindow;
047: import org.eclipse.ui.PartInitException;
048: import org.eclipse.ui.PlatformUI;
049:
050: import com.bostechcorp.cbesb.common.i18n.I18N;
051: import com.bostechcorp.cbesb.common.i18n.Messages;
052:
053: public class TestEditorWizardPage extends WizardPage {
054: private Text textFile;
055:
056: private ArrayList<String> list;
057:
058: protected TestEditorWizardPage(String pageName, String title,
059: ImageDescriptor titleImage, ArrayList<String> list) {
060: super (pageName, title, titleImage);
061: this .list = list;
062: setDescription(title);
063:
064: }
065:
066: private IWorkbench workbench;
067:
068: private Button openFileCheckbox;
069:
070: private Button buttonNewLine;
071:
072: private Button buttonEOF;
073:
074: private Combo combo;
075:
076: public void createControl(Composite parent) {
077: setControl(parent);
078: parent.setLayout(new FillLayout());
079: Composite composite = (Composite) getControl();
080: Composite main = new Composite(composite, SWT.NULL);
081: main.setLayout(new GridLayout());
082:
083: final Group choseDataFileGroup = new Group(main, SWT.NONE);
084: final GridLayout gridLayout = new GridLayout();
085: gridLayout.numColumns = 2;
086: choseDataFileGroup.setLayout(gridLayout);
087: choseDataFileGroup.setLayoutData(new GridData(SWT.FILL,
088: SWT.CENTER, true, false));
089: choseDataFileGroup.setText(I18N
090: .getString(Messages.CHOOSE_DATA_FILE));
091:
092: textFile = new Text(choseDataFileGroup, SWT.BORDER);
093: textFile.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
094: false));
095:
096: final Button buttonBrows = new Button(choseDataFileGroup,
097: SWT.NONE);
098: buttonBrows.addSelectionListener(new SelectionAdapter() {
099: public void widgetSelected(final SelectionEvent e) {
100:
101: FileDialog dlg = new FileDialog(PlatformUI
102: .getWorkbench().getActiveWorkbenchWindow()
103: .getShell(), SWT.APPLICATION_MODAL);
104: dlg.setFilterNames(new String[] { " (*.mdl)",
105: "All Files (*.*)" });
106: dlg.setFilterPath(((TestEditorWizard) getWizard())
107: .getProjectLocation().toString()
108: + "/src/test/");
109: textFile.setText(dlg.open());
110: setPageComplete(true);
111: getWizard().canFinish();
112: }
113: });
114: buttonBrows.setText(I18N.getString(Messages.WIZARD_BROWSE));
115:
116: final Group readStyleGroup = new Group(main, SWT.NONE);
117: readStyleGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
118: true, false));
119: readStyleGroup.setText(I18N.getString(Messages.READ_STYLE));
120: final FillLayout fillLayout = new FillLayout();
121: fillLayout.marginHeight = 5;
122: readStyleGroup.setLayout(fillLayout);
123:
124: buttonEOF = new Button(readStyleGroup, SWT.RADIO);
125: buttonEOF.setText("End of file");
126: buttonEOF.setSelection(true);
127:
128: buttonNewLine = new Button(readStyleGroup, SWT.RADIO);
129: buttonNewLine.setText("New Line");
130:
131: if (list != null && list.size() > 0) {
132: final Group chooseRootMessageGroup = new Group(main,
133: SWT.READ_ONLY);
134: chooseRootMessageGroup.setLayoutData(new GridData(SWT.FILL,
135: SWT.CENTER, false, false));
136: chooseRootMessageGroup.setText(I18N
137: .getString(Messages.TEST_SELECT_ROOT));
138: chooseRootMessageGroup.setLayout(new GridLayout());
139: combo = new Combo(chooseRootMessageGroup, SWT.READ_ONLY);
140: combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
141: true, false));
142: for (int i = 0; i < list.size(); i++) {
143: combo.add(list.get(i));
144: }
145: combo.select(0);
146:
147: }
148:
149: composite.setLayout(new FillLayout());
150:
151: }
152:
153: /**
154: * Creates a new file resource as requested by the user. If everything is OK
155: * then answer true. If not, false will cause the dialog to stay open.
156: *
157: * @return whether creation was successful
158: * @see MapTestingEditorWizard#performFinish()
159: */
160: public boolean finish() throws PartInitException {
161: if (openFileCheckbox.getSelection()) {
162: IWorkbenchWindow dwindow = workbench
163: .getActiveWorkbenchWindow();
164: IWorkbenchPage page = dwindow.getActivePage();
165: if (page != null) {
166: }
167: }
168: return true;
169: }
170:
171: /**
172: * The <code>MessageFormatCreationWizardPage</code> implementation of this
173: * <code>WizardNewFileCreationPage</code> method generates sample headings
174: * for sections and subsections in the newly-created Readme file according
175: * to the selections of self's checkbox widgets
176: */
177: protected InputStream getInitialContents() {
178: return null;
179: }
180:
181: /**
182: * Creates a new file resource as requested by the user. If everything is OK
183: * then answer true. If not, false will cause the dialog to stay open.
184: *
185: * @return whether creation was successful
186: * @see FormatTestWizard#performFinish()
187: */
188:
189: public boolean isPageComplete() {
190: if (!textFile.getText().equals(""))
191: return true;
192: else
193: return false;
194: }
195:
196: public void handleEvent(Event event) {
197: }
198:
199: public Text getTextFile() {
200: return textFile;
201: }
202:
203: public void setTextFile(Text textFile) {
204: this .textFile = textFile;
205: }
206:
207: public Button getButtonEOF() {
208: return buttonEOF;
209: }
210:
211: public void setButtonEOF(Button buttonEOF) {
212: this .buttonEOF = buttonEOF;
213: }
214:
215: public Button getButtonNewLine() {
216: return buttonNewLine;
217: }
218:
219: public void setButtonNewLine(Button buttonNewLine) {
220: this .buttonNewLine = buttonNewLine;
221: }
222:
223: public Combo getCombo() {
224: return combo;
225: }
226: }
|