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 org.eclipse.core.resources.IContainer;
027: import org.eclipse.core.resources.IResource;
028: import org.eclipse.jface.dialogs.IDialogPage;
029: import org.eclipse.jface.viewers.ISelection;
030: import org.eclipse.jface.viewers.IStructuredSelection;
031: import org.eclipse.jface.wizard.WizardPage;
032: import org.eclipse.swt.SWT;
033: import org.eclipse.swt.events.ModifyEvent;
034: import org.eclipse.swt.events.ModifyListener;
035: import org.eclipse.swt.events.SelectionAdapter;
036: import org.eclipse.swt.events.SelectionEvent;
037: import org.eclipse.swt.layout.FillLayout;
038: import org.eclipse.swt.layout.GridData;
039: import org.eclipse.swt.layout.GridLayout;
040: import org.eclipse.swt.widgets.Button;
041: import org.eclipse.swt.widgets.Combo;
042: import org.eclipse.swt.widgets.Composite;
043: import org.eclipse.swt.widgets.Group;
044: import org.eclipse.swt.widgets.Label;
045: import org.eclipse.swt.widgets.Text;
046: import org.eclipse.ui.IWorkbench;
047:
048: import com.bostechcorp.cbesb.common.i18n.I18N;
049: import com.bostechcorp.cbesb.common.i18n.Messages;
050: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
051: import com.bostechcorp.cbesb.common.util.FileUtil;
052: import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
053: import com.bostechcorp.cbesb.ui.etl.Activator;
054: import com.bostechcorp.cbesb.ui.util.MsgUtil;
055: import com.bostechcorp.cbesb.ui.util.browser.BaseFileBrowser;
056:
057: /**
058: * The "New" wizard page allows setting the container for the new file as well
059: * as the file name. The page will only accept file name without the extension
060: * OR with the extension that matches the expected one (mpe).
061: */
062:
063: public class DataSourceMapperSecondPage extends WizardPage {
064: private Text contentText;
065:
066: private Text textConnection;
067:
068: private Combo comboType;
069:
070: private IWorkbench workbench;
071:
072: private ISelection selection;
073:
074: private Text textName;
075:
076: /**
077: * Constructor for TransformerFormatCreationWizardPage.
078: *
079: * @param workbench
080: * @param selection
081: */
082: public DataSourceMapperSecondPage(IWorkbench workbench,
083: ISelection selection) {
084: super ("NewDataSourceMapperSecondPage");
085: this .workbench = workbench;
086: this .selection = selection;
087: setDescription(I18N.getString(Messages.WIZARD_ENTER_TIP));
088: setTitle(I18N.getString(Messages.NEW_DATA_SOURCE_MAPPER_FILE));
089: }
090:
091: /**
092: * @see IDialogPage#createControl(Composite)
093: */
094: public void createControl(Composite parent) {
095:
096: Composite container = new Composite(parent, SWT.NULL);
097: GridLayout layout = new GridLayout();
098: container.setLayout(layout);
099: layout.numColumns = 4;
100: layout.verticalSpacing = 9;
101:
102: final Label dataSourceMapperLabel = new Label(container,
103: SWT.NONE);
104: dataSourceMapperLabel.setLayoutData(new GridData());
105: dataSourceMapperLabel.setText(I18N
106: .getString(Messages.DATA_SOURCE_MAP)
107: + I18N.getString(Messages.NAME));
108:
109: textName = new Text(container, SWT.BORDER);
110: textName.addModifyListener(new ModifyListener() {
111: public void modifyText(final ModifyEvent e) {
112: modifyChanged();
113: }
114: });
115:
116: final GridData gridData_1 = new GridData(SWT.FILL, SWT.CENTER,
117: true, false, 3, 1);
118: gridData_1.widthHint = 400;
119: textName.setLayoutData(gridData_1);
120: final Label rootLabel = new Label(container, SWT.NULL);
121: rootLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
122: false, false));
123: rootLabel.setText(I18N.getString(Messages.CONNECTION_FILE));
124: textConnection = new Text(container, SWT.READ_ONLY | SWT.BORDER);
125: textConnection.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
126: true, false));
127: textConnection.addModifyListener(new ModifyListener() {
128: public void modifyText(final ModifyEvent e) {
129: modifyChanged();
130: }
131: });
132: final Button viewButton = new Button(container, SWT.NONE);
133: viewButton.addSelectionListener(new SelectionAdapter() {
134: public void widgetSelected(SelectionEvent e) {
135: if (textConnection.getText().equals(""))
136: return;
137: contentText.setText("");
138: try {
139: String fileName = EsbPathHelper
140: .getFullPathForDef(MacroUtil
141: .resolveBuiltinMacro(textConnection
142: .getText(),
143: getProjectName()));
144: String content = FileUtil
145: .readStringFromFile(fileName);
146: contentText.setText(content);
147: } catch (Exception ex) {
148: ex.printStackTrace();
149: MsgUtil.warningMsg(ex.toString());
150: }
151: }
152: });
153: viewButton.setLayoutData(new GridData());
154: viewButton.setText(I18N
155: .getString(Messages.CMW_ADVANCED_LABEL_VIEW_BUTTON));
156: final Button browseButton = new Button(container, SWT.NONE);
157: browseButton.addSelectionListener(new SelectionAdapter() {
158: public void widgetSelected(SelectionEvent e) {
159: browseListener(".dbc", textConnection);
160: }
161: });
162: browseButton.setLayoutData(new GridData());
163: browseButton.setText(I18N.getString(Messages.WIZARD_BROWSE));
164: initialize();
165: setControl(container);
166: final Label locationLabel = new Label(container, SWT.NONE);
167: locationLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
168: false, false));
169: locationLabel.setText(I18N
170: .getString(Messages.DATA_SOURCE_MAPPER_TYPE));
171:
172: comboType = new Combo(container, SWT.READ_ONLY);
173: comboType.setItems(new String[] { "HIERARCHICAL", "FLAT" });
174: comboType.select(1);
175: comboType.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
176: true, false, 3, 1));
177:
178: final Group composite = new Group(container, SWT.NONE);
179: composite.setLayout(new FillLayout());
180: composite.setText(I18N.getString(Messages.CONNECTION_FILE));
181: final GridData gridData = new GridData(SWT.FILL, SWT.FILL,
182: false, true, 4, 1);
183: gridData.heightHint = 220;
184: composite.setLayoutData(gridData);
185:
186: contentText = new Text(composite, SWT.V_SCROLL | SWT.READ_ONLY
187: | SWT.BORDER);
188: textName.setText(((DataSourceMapperMainPage) this
189: .getPreviousPage()).getFileName());
190: modifyChanged();
191: }
192:
193: /**
194: * Tests if the current workbench selection is a suitable container to use.
195: */
196:
197: private void initialize() {
198: if (selection != null && selection.isEmpty() == false
199: && selection instanceof IStructuredSelection) {
200: IStructuredSelection ssel = (IStructuredSelection) selection;
201: if (ssel.size() > 1)
202: return;
203:
204: Object obj = ssel.getFirstElement();
205: if (obj instanceof IResource) {
206: IContainer container = null;
207: if (obj instanceof IContainer)
208: container = (IContainer) obj;
209: else
210: container = ((IResource) obj).getParent();
211: }
212: }
213: }
214:
215: private void updateStatus(String message) {
216: setErrorMessage(message);
217: setPageComplete(message == null && isPageComplete());
218: this .getWizard().canFinish();
219: }
220:
221: public String getFileName() {
222: return "";
223: }
224:
225: public void modifyChanged() {
226: if (textName.getText().equals("")) {
227: setErrorMessage(I18N.getString(Messages.NAME_REQ));
228: setPageComplete(false);
229: return;
230: }
231: if (textConnection.getText().equals("")) {
232: setErrorMessage(I18N.getString(Messages.CONNECTION_REQ));
233: setPageComplete(false);
234: return;
235: }
236: setErrorMessage(null);
237: setPageComplete(true);
238: }
239:
240: public boolean finish() {
241: return false;
242: }
243:
244: public Combo getComboType() {
245: return comboType;
246: }
247:
248: public Text getTextConnection() {
249: return textConnection;
250: }
251:
252: public void browseListener(String postfix, Text text) {
253: BaseFileBrowser browser = new BaseFileBrowser(Activator
254: .getDefault(), text.getShell(), text, getProjectName(),
255: postfix, "database/connections", I18N
256: .getString(Messages.SELECT_CONNECTION_FILE));
257: browser.open();
258: }
259:
260: public String getProjectName() {
261: return ((DataSourceMapperMainPage) this .getPreviousPage())
262: .getSelectProjectName();
263: }
264:
265: /**
266: * @return the textName
267: */
268: public Text getTextName() {
269: return textName;
270: }
271:
272: /**
273: * @param textName
274: * the textName to set
275: */
276: public void setTextName(Text textName) {
277: this.textName = textName;
278: }
279: }
|