001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.designstudio.editors.actionsequence.pages.actions.details;
014:
015: import java.io.BufferedReader;
016: import java.io.FileReader;
017: import java.util.ArrayList;
018: import java.util.Arrays;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import java.util.regex.Matcher;
022: import java.util.regex.Pattern;
023:
024: import org.eclipse.core.runtime.IPath;
025: import org.eclipse.core.runtime.Path;
026: import org.eclipse.swt.SWT;
027: import org.eclipse.swt.custom.StackLayout;
028: import org.eclipse.swt.events.FocusEvent;
029: import org.eclipse.swt.events.FocusListener;
030: import org.eclipse.swt.events.SelectionEvent;
031: import org.eclipse.swt.events.SelectionListener;
032: import org.eclipse.swt.layout.GridData;
033: import org.eclipse.swt.layout.GridLayout;
034: import org.eclipse.swt.widgets.Button;
035: import org.eclipse.swt.widgets.Composite;
036: import org.eclipse.swt.widgets.FileDialog;
037: import org.eclipse.swt.widgets.Text;
038: import org.pentaho.actionsequence.dom.AbstractIOElement;
039: import org.pentaho.actionsequence.dom.ActionInput;
040: import org.pentaho.actionsequence.dom.ActionInputConstant;
041: import org.pentaho.actionsequence.dom.ActionOutput;
042: import org.pentaho.actionsequence.dom.ActionResource;
043: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
044: import org.pentaho.actionsequence.dom.ActionSequenceInput;
045: import org.pentaho.actionsequence.dom.ActionSequenceResource;
046: import org.pentaho.actionsequence.dom.IActionInputValueProvider;
047: import org.pentaho.actionsequence.dom.IActionSequenceElement;
048: import org.pentaho.actionsequence.dom.actions.TemplateMsgAction;
049: import org.pentaho.designstudio.controls.ActionOutputText;
050: import org.pentaho.designstudio.controls.ActionResourceText;
051: import org.pentaho.designstudio.controls.NewActionInputCombo;
052: import org.pentaho.designstudio.controls.NewActionInputText;
053: import org.pentaho.designstudio.controls.TemplateMsgInputsTable;
054: import org.pentaho.designstudio.controls.TemplateMsgInputsTableToolbar;
055: import org.pentaho.designstudio.controls.WidgetFactory;
056: import org.pentaho.designstudio.editors.actionsequence.pages.actions.IActionIOFilter;
057: import org.pentaho.designstudio.messages.Messages;
058: import org.pentaho.designstudio.util.SolutionHelper;
059:
060: /**
061: * The template describing the action definition used to display templated strings.
062: *
063: * @author Angelo Rodriguez
064: */
065: public class TemplateMessageDetailsPage extends ActionDetailsPage
066: implements IActionIOFilter, SelectionListener, FocusListener {
067:
068: public static final String DISPLAY_NAME = Messages
069: .getString("TemplateMessageDetailsPage.UI_COMPONENT_NAME_TEMPLATE"); //$NON-NLS-1$
070:
071: Composite staticMsgComposite;
072: NewActionInputText staticMsgText;
073: ActionOutputText staticOutputName;
074:
075: Composite fileComposite;
076: ActionOutputText fileOutputName;
077: ActionResourceText msgFile;
078: Button fileBrowserBtn;
079:
080: Composite paramComposite;
081: ActionOutputText paramOutputName;
082: NewActionInputCombo inputParam;
083:
084: TemplateMsgInputsTable msgParametersTable;
085: TemplateMsgInputsTableToolbar msgParamsToolbar;
086:
087: Composite stackedComposite;
088: StackLayout stackLayout;
089:
090: Composite variableMsgComposite;
091: Composite variableStackedComposite;
092: StackLayout variableStackLayout;
093:
094: Button staticMessageBtn;
095: Button inputMessageBtn;
096: Button resourceMessageBtn;
097:
098: String originalResourceFileName;
099:
100: IPath basePath;
101:
102: public static final String SOLUTION_FILE_PREFIX = "solution:"; //$NON-NLS-1$
103:
104: /**
105: * Creates a templated message template.
106: */
107: public TemplateMessageDetailsPage(IPath basePath) {
108: super ();
109: this .basePath = basePath;
110: }
111:
112: public String getComponentName() {
113: return TemplateMsgAction.COMPONENT_NAME;
114: }
115:
116: public String getName() {
117: return DISPLAY_NAME;
118: }
119:
120: private void createStaticMsgComposite(Composite parent) {
121: staticMsgComposite = WidgetFactory.createComposite(parent);
122: GridLayout gridLayout = new GridLayout(2, true);
123: gridLayout.marginWidth = 1;
124: gridLayout.marginHeight = 2;
125: staticMsgComposite.setLayout(gridLayout);
126:
127: GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
128: layoutData.horizontalSpan = 2;
129: WidgetFactory
130: .createLabel(
131: staticMsgComposite,
132: Messages
133: .getString("TemplateMessageDetailsPage.UI_TEMPLATE_HEADER_LABEL")).setLayoutData(layoutData); //$NON-NLS-1$
134:
135: layoutData = new GridData(GridData.FILL_BOTH);
136: layoutData.horizontalSpan = 2;
137: staticMsgText = new NewActionInputText(staticMsgComposite,
138: layoutData, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL
139: | SWT.BORDER);
140:
141: layoutData = new GridData();
142: layoutData.horizontalSpan = 2;
143: WidgetFactory
144: .createLabel(staticMsgComposite, "").setLayoutData(layoutData); //$NON-NLS-1$
145:
146: layoutData = new GridData();
147: layoutData.horizontalSpan = 2;
148: WidgetFactory
149: .createLabel(
150: staticMsgComposite,
151: Messages
152: .getString("TemplateMessageDetailsPage.UI_OUTPUT_STRING_NAME_LABEL")).setLayoutData(layoutData); //$NON-NLS-1$
153:
154: staticOutputName = new ActionOutputText(staticMsgComposite,
155: new GridData(GridData.FILL_HORIZONTAL));
156: }
157:
158: private void createFileComposite(Composite parent) {
159:
160: fileComposite = WidgetFactory.createComposite(parent);
161: GridLayout gridLayout = new GridLayout();
162: gridLayout.marginWidth = 1;
163: gridLayout.marginHeight = 1;
164: fileComposite.setLayout(gridLayout);
165:
166: WidgetFactory
167: .createLabel(
168: fileComposite,
169: Messages
170: .getString("TemplateMessageDetailsPage.RESOURCE_FILE_NAME"), SWT.NONE); //$NON-NLS-1$
171: msgFile = new ActionResourceText(fileComposite, new GridData(
172: GridData.FILL_HORIZONTAL));
173: msgFile.getControl().addFocusListener(this );
174: fileBrowserBtn = WidgetFactory
175: .createButton(
176: fileComposite,
177: Messages
178: .getString("JFreeReportDetailsPage.UI_BROWSE_LABEL"), SWT.FLAT); //$NON-NLS-1$
179: fileBrowserBtn.addSelectionListener(this );
180: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
181: gridData.horizontalAlignment = GridData.END;
182: fileBrowserBtn.setLayoutData(gridData);
183:
184: WidgetFactory
185: .createLabel(
186: fileComposite,
187: Messages
188: .getString("TemplateMessageDetailsPage.UI_OUTPUT_STRING_NAME_LABEL")).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); //$NON-NLS-1$
189: fileOutputName = new ActionOutputText(fileComposite,
190: new GridData(GridData.FILL_HORIZONTAL));
191: }
192:
193: private void createParamComposite(Composite parent) {
194: paramComposite = WidgetFactory.createComposite(parent);
195: GridLayout gridLayout = new GridLayout();
196: gridLayout.marginWidth = 1;
197: gridLayout.marginHeight = 1;
198: paramComposite.setLayout(gridLayout);
199:
200: WidgetFactory
201: .createLabel(
202: paramComposite,
203: Messages
204: .getString("TemplateMessageDetailsPage.STRING_PARAMETER_NAME"), SWT.NONE); //$NON-NLS-1$
205: inputParam = new NewActionInputCombo(paramComposite,
206: new GridData(GridData.FILL_HORIZONTAL));
207: WidgetFactory.createLabel(paramComposite, "", SWT.NONE); //$NON-NLS-1$
208:
209: WidgetFactory
210: .createLabel(
211: paramComposite,
212: Messages
213: .getString("TemplateMessageDetailsPage.UI_OUTPUT_STRING_NAME_LABEL")).setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); //$NON-NLS-1$
214: paramOutputName = new ActionOutputText(paramComposite,
215: new GridData(GridData.FILL_HORIZONTAL));
216: }
217:
218: private void createVariableMsgComposite(Composite parent) {
219: variableMsgComposite = WidgetFactory.createComposite(parent);
220: GridLayout gridLayout = new GridLayout(2, true);
221: gridLayout.marginWidth = 1;
222: gridLayout.marginHeight = 2;
223: variableMsgComposite.setLayout(gridLayout);
224: variableStackedComposite = WidgetFactory
225: .createComposite(variableMsgComposite);
226: variableStackLayout = new StackLayout();
227: variableStackedComposite.setLayout(variableStackLayout);
228: GridData gridData = new GridData(GridData.FILL_BOTH);
229: gridData.verticalSpan = 2;
230: variableStackedComposite.setLayoutData(gridData);
231:
232: Composite composite = WidgetFactory
233: .createComposite(variableMsgComposite);
234: gridLayout = new GridLayout(2, false);
235: gridLayout.marginWidth = 0;
236: gridLayout.marginHeight = 0;
237: composite.setLayout(gridLayout);
238: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
239: WidgetFactory
240: .createLabel(
241: composite,
242: Messages
243: .getString("TemplateMessageDetailsPage.MSG_TEMPLATE_PARAMETERS")); //$NON-NLS-1$
244:
245: msgParametersTable = new TemplateMsgInputsTable(
246: variableMsgComposite);
247: msgParametersTable.getTable().setLayoutData(
248: new GridData(GridData.FILL_BOTH));
249:
250: msgParamsToolbar = new TemplateMsgInputsTableToolbar(composite,
251: msgParametersTable);
252: gridData = new GridData(GridData.FILL_HORIZONTAL);
253: gridData.horizontalAlignment = GridData.END;
254: msgParamsToolbar.getControl().setLayoutData(gridData);
255:
256: createFileComposite(variableStackedComposite);
257: createParamComposite(variableStackedComposite);
258: }
259:
260: public void createDetailsComposite(Composite parent) {
261: Composite actionConfigComposite = parent;
262:
263: GridLayout layout = new GridLayout(3, false);
264: actionConfigComposite.setLayout(layout);
265:
266: GridData layoutData = new GridData(GridData.FILL_HORIZONTAL);
267: layoutData.horizontalSpan = 3;
268: WidgetFactory
269: .createLabel(actionConfigComposite, "").setLayoutData(layoutData); //$NON-NLS-1$
270: layoutData = new GridData(GridData.FILL_HORIZONTAL);
271: layoutData.horizontalSpan = 3;
272: WidgetFactory
273: .createLabel(
274: actionConfigComposite,
275: Messages
276: .getString("TemplateMessageDetailsPage.SOURC_OF_MSG_TEMPLATE")).setLayoutData(layoutData); //$NON-NLS-1$
277:
278: staticMessageBtn = WidgetFactory
279: .createButton(
280: actionConfigComposite,
281: Messages
282: .getString("TemplateMessageDetailsPage.TEXT_RADIO_OPTION"), SWT.RADIO); //$NON-NLS-1$
283: staticMessageBtn.addSelectionListener(this );
284: resourceMessageBtn = WidgetFactory
285: .createButton(
286: actionConfigComposite,
287: Messages
288: .getString("TemplateMessageDetailsPage.USE_RESOURCE_RADIO_OPTION"), SWT.RADIO); //$NON-NLS-1$
289: resourceMessageBtn.addSelectionListener(this );
290: inputMessageBtn = WidgetFactory
291: .createButton(
292: actionConfigComposite,
293: Messages
294: .getString("TemplateMessageDetailsPage.USE_STRING_PARAM_RADIO_OPTION"), SWT.RADIO); //$NON-NLS-1$
295: inputMessageBtn.addSelectionListener(this );
296: layoutData = new GridData(GridData.FILL_HORIZONTAL);
297: layoutData.horizontalSpan = 3;
298: WidgetFactory
299: .createLabel(actionConfigComposite, "").setLayoutData(layoutData); //$NON-NLS-1$
300:
301: stackedComposite = WidgetFactory
302: .createComposite(actionConfigComposite);
303: layoutData = new GridData(GridData.FILL_BOTH);
304: layoutData.horizontalSpan = 3;
305: stackedComposite.setLayoutData(layoutData);
306: stackLayout = new StackLayout();
307: stackedComposite.setLayout(stackLayout);
308:
309: createStaticMsgComposite(stackedComposite);
310: createVariableMsgComposite(stackedComposite);
311: }
312:
313: public void refresh() {
314: super .refresh();
315: TemplateMsgAction templateMsgAction = (TemplateMsgAction) actionDefinition;
316: staticMsgText.setTargetInput(templateMsgAction,
317: TemplateMsgAction.TEMPLATE_ELEMENT);
318: staticOutputName.setTargetOutput(templateMsgAction,
319: TemplateMsgAction.OUTPUT_STRING);
320: fileOutputName.setTargetOutput(templateMsgAction,
321: TemplateMsgAction.OUTPUT_STRING);
322: paramOutputName.setTargetOutput(templateMsgAction,
323: TemplateMsgAction.OUTPUT_STRING);
324: inputParam.setTargetInput(templateMsgAction,
325: TemplateMsgAction.TEMPLATE_ELEMENT,
326: ActionSequenceDocument.STRING_TYPE);
327: msgFile.setTargetResource(templateMsgAction,
328: TemplateMsgAction.TEMPLATE_RESOURCE);
329: msgParametersTable.setInput(templateMsgAction);
330: inputMessageBtn.removeSelectionListener(this );
331: staticMessageBtn.removeSelectionListener(this );
332: resourceMessageBtn.removeSelectionListener(this );
333:
334: IActionInputValueProvider templateInput = templateMsgAction
335: .getTemplate();
336: if (((templateInput instanceof ActionInput) || (templateInput == IActionInputValueProvider.NULL_INPUT))
337: && (templateMsgAction
338: .getResourceParam(TemplateMsgAction.TEMPLATE_ELEMENT) == null)) {
339: stackLayout.topControl = variableMsgComposite;
340: variableStackLayout.topControl = paramComposite;
341: variableStackedComposite.layout();
342: stackedComposite.layout();
343: inputMessageBtn.setSelection(true);
344: staticMessageBtn.setSelection(false);
345: resourceMessageBtn.setSelection(false);
346: } else if ((templateMsgAction
347: .getResourceParam(TemplateMsgAction.TEMPLATE_ELEMENT) != null)
348: && (templateInput == IActionInputValueProvider.NULL_INPUT)) {
349: stackLayout.topControl = variableMsgComposite;
350: variableStackLayout.topControl = fileComposite;
351: variableStackedComposite.layout();
352: stackedComposite.layout();
353: inputMessageBtn.setSelection(false);
354: staticMessageBtn.setSelection(false);
355: resourceMessageBtn.setSelection(true);
356: } else if ((templateInput != IActionInputValueProvider.NULL_INPUT)
357: && !(templateInput instanceof ActionInput)
358: && (templateMsgAction
359: .getResourceParam(TemplateMsgAction.TEMPLATE_ELEMENT) == null)) {
360: stackLayout.topControl = staticMsgComposite;
361: stackedComposite.layout();
362: inputMessageBtn.setSelection(false);
363: staticMessageBtn.setSelection(true);
364: resourceMessageBtn.setSelection(false);
365: } else {
366: stackLayout.topControl = null;
367: stackedComposite.layout();
368: inputMessageBtn.setSelection(false);
369: staticMessageBtn.setSelection(false);
370: resourceMessageBtn.setSelection(false);
371: }
372: inputMessageBtn.addSelectionListener(this );
373: staticMessageBtn.addSelectionListener(this );
374: resourceMessageBtn.addSelectionListener(this );
375: msgParamsToolbar.refresh();
376: }
377:
378: public boolean accepts(IActionSequenceElement actionDef) {
379: return actionDef instanceof TemplateMsgAction;
380: }
381:
382: public boolean accept(AbstractIOElement ioElement) {
383: boolean result = false;
384: if ((ioElement instanceof ActionSequenceInput)
385: || (ioElement instanceof ActionInput)) {
386: result = !ioElement.getName().equals(
387: TemplateMsgAction.TEMPLATE_ELEMENT)
388: && ioElement.getType().equals(
389: ActionSequenceDocument.STRING_TYPE);
390: } else if (ioElement instanceof ActionOutput) {
391: result = !((ActionOutput) ioElement).getPublicName()
392: .equals(TemplateMsgAction.TEMPLATE_ELEMENT)
393: && ioElement.getType().equals(
394: ActionSequenceDocument.STRING_TYPE);
395: }
396: return result;
397: }
398:
399: private void setResourcePath(String fileName, Text text) {
400: String fileSolution = SolutionHelper.getSolutionName(fileName);
401: Path filePath = new Path(fileName);
402: String baseSolution = SolutionHelper.getSolutionName(basePath
403: .toString());
404: String solutionRoot = SolutionHelper.getSolutionRoot(basePath
405: .toString());
406:
407: if ((baseSolution != null) && baseSolution.equals(fileSolution)) {
408: if (filePath.matchingFirstSegments(basePath) == basePath
409: .segmentCount()) {
410: IPath relativeFilePath = filePath
411: .removeFirstSegments(basePath.segmentCount());
412: text.setText(relativeFilePath.setDevice(
413: ActionSequenceResource.SOLUTION_SCHEME + ":")
414: .toString());
415: } else {
416: Path solutionPath = new Path(solutionRoot);
417: IPath relativePath = filePath
418: .removeFirstSegments(solutionPath
419: .segmentCount());
420: IPath absPath = relativePath.makeAbsolute().setDevice(
421: ActionSequenceResource.SOLUTION_SCHEME + ":"); //$NON-NLS-1$
422: text.setText(absPath.toString());
423: }
424: } else {
425: text.setText(ActionSequenceResource.FILE_SCHEME + ":"
426: + fileName);
427: }
428: }
429:
430: public void widgetDefaultSelected(SelectionEvent e) {
431: }
432:
433: public void widgetSelected(SelectionEvent e) {
434: Button button = (Button) e.getSource();
435: TemplateMsgAction templateMsgAction = (TemplateMsgAction) actionDefinition;
436: if ((button == staticMessageBtn)
437: || (button == resourceMessageBtn)
438: || (button == inputMessageBtn)) {
439: if (button.getSelection()) {
440: if (button == inputMessageBtn) {
441: ActionResource[] actionResources = templateMsgAction
442: .getAllResourceParams();
443: ArrayList resourceNames = new ArrayList();
444: for (int i = 0; i < actionResources.length; i++) {
445: resourceNames.add(actionResources[i]
446: .getPublicName());
447: }
448: templateMsgAction.clearResourceParams();
449: for (Iterator iter = resourceNames.iterator(); iter
450: .hasNext();) {
451: ActionSequenceResource actionSequenceResource = templateMsgAction
452: .getDocument().getResource(
453: iter.next().toString());
454: if (actionSequenceResource != null) {
455: if (templateMsgAction.getDocument()
456: .getReferencesTo(
457: actionSequenceResource).length == 0) {
458: actionSequenceResource.delete();
459: }
460: }
461: }
462: templateMsgAction.setTemplate(null);
463: } else if (button == resourceMessageBtn) {
464: templateMsgAction.setTemplate(null);
465: ActionResource actionResource = templateMsgAction
466: .addResourceParam(TemplateMsgAction.TEMPLATE_ELEMENT);
467: String logicalName = actionResource.getPublicName();
468: int index = 1;
469: while (actionResource.getDocument().getResource(
470: logicalName) != null) {
471: logicalName = actionResource.getPublicName()
472: + Integer.toString(index++);
473: }
474: actionResource.setMapping(logicalName);
475: } else if (button == staticMessageBtn) {
476: ActionResource[] actionResources = templateMsgAction
477: .getAllResourceParams();
478: ArrayList resourceNames = new ArrayList();
479: for (int i = 0; i < actionResources.length; i++) {
480: resourceNames.add(actionResources[i]
481: .getPublicName());
482: }
483: templateMsgAction.clearResourceParams();
484: for (Iterator iter = resourceNames.iterator(); iter
485: .hasNext();) {
486: ActionSequenceResource actionSequenceResource = templateMsgAction
487: .getDocument().getResource(
488: iter.next().toString());
489: if (actionSequenceResource != null) {
490: if (templateMsgAction.getDocument()
491: .getReferencesTo(
492: actionSequenceResource).length == 0) {
493: actionSequenceResource.delete();
494: }
495: }
496: }
497: templateMsgAction
498: .removeInputParam(TemplateMsgAction.TEMPLATE_ELEMENT);
499: templateMsgAction
500: .setTemplate(new ActionInputConstant(""));
501: }
502: ActionInput[] actionInputs = templateMsgAction
503: .getAllInputParams();
504: for (int i = 0; i < actionInputs.length; i++) {
505: if (!actionInputs[i].getName().equals(
506: TemplateMsgAction.TEMPLATE_ELEMENT)) {
507: actionInputs[i].delete();
508: }
509: }
510: refresh();
511: }
512: } else if (button == fileBrowserBtn) {
513: String originalFileName = msgFile.getText().trim();
514: if (originalFileName.equals(SOLUTION_FILE_PREFIX)) {
515: originalFileName = ""; //$NON-NLS-1$
516: }
517: FileDialog fileChooser = new FileDialog(fileBrowserBtn
518: .getShell(), SWT.OPEN);
519: fileChooser
520: .setText(Messages
521: .getString("TemplateMessageDetailsPage.SELECT_MSG_TEMPLATE")); //$NON-NLS-1$
522: fileChooser.setFilterExtensions(new String[] { "*.*" }); //$NON-NLS-1$
523: fileChooser.setFilterNames(new String[] { Messages
524: .getString("BIRTReportDetailsPage.ALL_FILES") }); //$NON-NLS-1$
525: fileChooser.setFilterPath(basePath.toString());
526: String filename = fileChooser.open();
527: if (filename != null) {
528: setResourcePath(filename, (Text) msgFile.getControl());
529: String newFileName = msgFile.getText().trim();
530: if (newFileName.equals(SOLUTION_FILE_PREFIX)) {
531: newFileName = ""; //$NON-NLS-1$
532: }
533: if (!newFileName.equals(originalFileName)) {
534: syncTemplateInputs();
535: }
536: }
537: }
538: }
539:
540: public HashSet getReferencedInputs(String string) {
541: HashSet queryInputs = new HashSet();
542: Pattern pattern = Pattern.compile("\\{[a-zA-Z_0-9\\-]+\\}"); //$NON-NLS-1$
543: Matcher matcher = pattern.matcher(string);
544: int startIndex = 0;
545: while (matcher.find() && (startIndex < string.length())) {
546: String inputName = matcher.group();
547: inputName = inputName.substring(1, inputName.length() - 1);
548: queryInputs.add(inputName);
549: }
550: return queryInputs;
551: }
552:
553: private void syncTemplateInputs() {
554: String resourceFileName = msgFile.getText().trim();
555: HashSet templateParams = new HashSet();
556: if (resourceFileName.length() > 0) {
557: IPath path = new Path(resourceFileName);
558: String filePath = path.toOSString();
559: try {
560: if (!path.isAbsolute()) {
561: if (SolutionHelper.getSolutionName(basePath
562: .toString()) != null) {
563: filePath = basePath.append(path).toOSString();
564: } else {
565: filePath = null;
566: }
567: } else if (path.getDevice()
568: .equals(SOLUTION_FILE_PREFIX)) {
569: String solutionRoot = SolutionHelper
570: .getSolutionRoot(basePath.toString());
571: if (solutionRoot != null) {
572: IPath solutionPath = new Path(solutionRoot);
573: filePath = solutionPath.append(path)
574: .toOSString();
575: } else {
576: filePath = null;
577: }
578: }
579: if (filePath != null) {
580: FileReader fileReader = new FileReader(filePath);
581: BufferedReader bufferedReader = new BufferedReader(
582: fileReader);
583: for (String line = bufferedReader.readLine(); line != null; line = bufferedReader
584: .readLine()) {
585: templateParams
586: .addAll(getReferencedInputs(line));
587: }
588: } else {
589: templateParams = null;
590: }
591: } catch (Exception ex) {
592: }
593: }
594:
595: if (templateParams != null) {
596: ActionInput[] actionInputs = actionDefinition
597: .getAllInputParams();
598: ArrayList expectedInputs = new ArrayList(Arrays
599: .asList(actionDefinition.getReservedInputNames()));
600: ArrayList inputNames = new ArrayList();
601: for (int i = 0; i < actionInputs.length; i++) {
602: if (!expectedInputs.contains(actionInputs[i].getName())
603: && !templateParams.contains(actionInputs[i]
604: .getName())) {
605: actionInputs[i].delete();
606: } else {
607: inputNames.add(actionInputs[i].getName());
608: }
609: }
610: for (Iterator iter = templateParams.iterator(); iter
611: .hasNext();) {
612: String paramName = (String) iter.next();
613: if (!inputNames.contains(paramName)) {
614: actionDefinition.addInputParam(paramName,
615: ActionSequenceDocument.STRING_TYPE);
616: }
617: }
618: msgParametersTable.refresh();
619: }
620: }
621:
622: public void focusGained(FocusEvent e) {
623: originalResourceFileName = msgFile.getText().trim();
624: if (originalResourceFileName.equals(SOLUTION_FILE_PREFIX)) {
625: originalResourceFileName = ""; //$NON-NLS-1$
626: }
627: }
628:
629: public void focusLost(FocusEvent e) {
630: String resourceFileName = msgFile.getText().trim();
631: if (resourceFileName.equals(SOLUTION_FILE_PREFIX)) {
632: resourceFileName = ""; //$NON-NLS-1$
633: }
634: if (!resourceFileName.equals(originalResourceFileName)) {
635: syncTemplateInputs();
636: }
637: }
638: }
|