001: package com.bostechcorp.cbesb.ui.ide.wizards;
002:
003: import java.io.File;
004:
005: import org.eclipse.core.resources.IContainer;
006: import org.eclipse.core.resources.IResource;
007: import org.eclipse.core.resources.ResourcesPlugin;
008: import org.eclipse.jface.viewers.ISelection;
009: import org.eclipse.jface.viewers.IStructuredSelection;
010: import org.eclipse.jface.wizard.IWizardPage;
011: import org.eclipse.jface.wizard.WizardPage;
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.ModifyEvent;
014: import org.eclipse.swt.events.ModifyListener;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.layout.GridLayout;
017: import org.eclipse.swt.widgets.Composite;
018: import org.eclipse.swt.widgets.Label;
019: import org.eclipse.swt.widgets.Text;
020: import org.eclipse.ui.IWorkbench;
021:
022: import com.bostechcorp.cbesb.common.i18n.I18N;
023: import com.bostechcorp.cbesb.common.i18n.Messages;
024:
025: public class CustomCodeWizardGroovyPage extends WizardPage {
026:
027: private Text textMethod;
028:
029: private Text textName;
030:
031: private Text sourceFolderText;
032:
033: private ISelection selection;
034:
035: private IWorkbench workbench;
036:
037: private Label methodLabel;
038:
039: private CustomCodeWizardGroovyPage _this ;
040:
041: private String delimiter = File.separator;
042:
043: /**
044: * Constructor for TransformerFormatCreationWizardPage.
045: *
046: * @param workbench
047: * @param selection
048: */
049: public CustomCodeWizardGroovyPage(IWorkbench workbench,
050: ISelection selection) {
051: super ("GroovyPage");
052: this .selection = selection;
053: this .workbench = workbench;
054: _this = this ;
055: setTitle(I18N.getString(Messages.CUSTOM_CODE_GROOVY_PAGE));// "Choose
056: setDescription(I18N.getString(Messages.WIZARD_ENTER_TIP));// "Choose
057:
058: }
059:
060: public void createControl(Composite parent) {
061:
062: final Composite composite = new Composite(parent, SWT.NONE);
063: final GridLayout gridLayout = new GridLayout();
064: gridLayout.marginTop = 5;
065: gridLayout.verticalSpacing = 10;
066: gridLayout.numColumns = 2;
067: composite.setLayout(gridLayout);
068:
069: final Label typeLabel = new Label(composite, SWT.NONE);
070: typeLabel.setText(I18N.getString(Messages.SOURCE_FOLDER));
071:
072: sourceFolderText = new Text(composite, SWT.READ_ONLY
073: | SWT.BORDER);
074: final GridData gridData = new GridData(SWT.FILL, SWT.CENTER,
075: true, false);
076: gridData.widthHint = 311;
077: sourceFolderText.setLayoutData(gridData);
078: sourceFolderText.setText(((CustomCodeWizard) _this .getWizard())
079: .getProjectFromSelection()
080: + delimiter + "src" + delimiter + "script");
081:
082: final Label nameLabel = new Label(composite, SWT.NONE);
083: nameLabel.setText(I18N.getString(Messages.NAME));
084:
085: textName = new Text(composite, SWT.BORDER);
086: textName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
087: false));
088: textName.addModifyListener(new ModifyListener() {
089:
090: public void modifyText(ModifyEvent e) {
091:
092: dialogChanged();
093:
094: }
095:
096: });
097: methodLabel = new Label(composite, SWT.NONE);
098: methodLabel.setLayoutData(new GridData());
099: methodLabel.setText(I18N.getString(Messages.METHOD));
100:
101: textMethod = new Text(composite, SWT.BORDER);
102: textMethod.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
103: true, false));
104: textMethod.setVisible(false);
105: textMethod.addModifyListener(new ModifyListener() {
106:
107: public void modifyText(ModifyEvent e) {
108:
109: dialogChanged();
110:
111: }
112:
113: });
114:
115: initialize();
116: setControl(composite);
117: dialogChanged();
118: }
119:
120: /**
121: * Ensures that both text fields are set.
122: */
123:
124: public void dialogChanged() {
125: if (sourceFolderText.getText().equals("")) {
126: setPageComplete(false);
127: updateStatus(I18N
128: .getString(Messages.CUSTOM_CODE_SOURCE_FOLDER_REQUIRED));
129: return;
130: }
131: if (textName.getText().equals("")) {
132: setPageComplete(false);
133: updateStatus(I18N.getString(Messages.NAME_REQUIRED));
134: return;
135: }
136: if (textMethod.isVisible() && textMethod.getText().equals("")) {
137: setPageComplete(false);
138: updateStatus(I18N.getString(Messages.METHOD_REQUIRED));
139: return;
140: }
141: setPageComplete(true);
142: updateStatus(null);
143: }
144:
145: public void updateStatus(String message) {
146: setErrorMessage(message);
147: }
148:
149: @Override
150: public IWizardPage getNextPage() {
151:
152: return null;
153: }
154:
155: public boolean finish() {
156: return false;
157: }
158:
159: public String getPath() {
160: String location = ResourcesPlugin.getWorkspace().getRoot()
161: .getLocation().toOSString();
162: return location + File.separator + sourceFolderText.getText();
163: }
164:
165: public String getName() {
166: return textName.getText();
167: }
168:
169: public String getMethod() {
170: return textMethod.getText();
171: }
172:
173: public void changeMethodVisable(boolean flag) {
174: methodLabel.setVisible(flag);
175: textMethod.setVisible(flag);
176: }
177:
178: private void initialize() {
179: if (selection != null && selection.isEmpty() == false
180: && selection instanceof IStructuredSelection) {
181: IStructuredSelection ssel = (IStructuredSelection) selection;
182: if (ssel.size() > 1)
183: return;
184: Object obj = ssel.getFirstElement();
185: if (obj instanceof IResource) {
186: IContainer container;
187: if (obj instanceof IContainer)
188: container = (IContainer) obj;
189: else
190: container = ((IResource) obj).getParent();
191: // targetfileNameText.setText(container.getFullPath().toString());
192: }
193: }
194: }
195:
196: public String getProjectName() {
197: String project = "";
198: if (sourceFolderText.getText().contains(File.separator)) {
199: project = sourceFolderText.getText().substring(0,
200: sourceFolderText.getText().indexOf(File.separator));
201: } else {
202: project = sourceFolderText.getText();
203: ;
204: }
205: return project;
206: }
207:
208: public Text getTextMethod() {
209:
210: return textMethod;
211: }
212:
213: }
|