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.reports;
014:
015: import org.eclipse.core.runtime.IPath;
016: import org.eclipse.core.runtime.Path;
017: import org.eclipse.swt.SWT;
018: import org.eclipse.swt.events.SelectionEvent;
019: import org.eclipse.swt.events.SelectionListener;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.layout.GridLayout;
022: import org.eclipse.swt.widgets.Button;
023: import org.eclipse.swt.widgets.Composite;
024: import org.eclipse.swt.widgets.FileDialog;
025: import org.eclipse.swt.widgets.Text;
026: import org.eclipse.ui.forms.widgets.Section;
027: import org.pentaho.actionsequence.dom.AbstractIOElement;
028: import org.pentaho.actionsequence.dom.ActionInput;
029: import org.pentaho.actionsequence.dom.ActionOutput;
030: import org.pentaho.actionsequence.dom.ActionSequenceDocument;
031: import org.pentaho.actionsequence.dom.ActionSequenceInput;
032: import org.pentaho.actionsequence.dom.ActionSequenceResource;
033: import org.pentaho.actionsequence.dom.IActionSequenceElement;
034: import org.pentaho.actionsequence.dom.actions.ActionDefinition;
035: import org.pentaho.actionsequence.dom.actions.BirtReportAction;
036: import org.pentaho.designstudio.controls.ActionInputsList;
037: import org.pentaho.designstudio.controls.ActionInputsListToolbar;
038: import org.pentaho.designstudio.controls.ActionOutputText;
039: import org.pentaho.designstudio.controls.ActionResourceText;
040: import org.pentaho.designstudio.controls.NewActionInputCombo;
041: import org.pentaho.designstudio.controls.WidgetFactory;
042: import org.pentaho.designstudio.editors.actionsequence.pages.actions.IActionIOFilter;
043: import org.pentaho.designstudio.editors.actionsequence.pages.actions.details.ActionDetailsPage;
044: import org.pentaho.designstudio.messages.Messages;
045: import org.pentaho.designstudio.util.SolutionHelper;
046:
047: /**
048: * The template describing the Birt report action definition.
049: *
050: * @author Angelo Rodriguez
051: */
052: public class BIRTReportDetailsPage extends ActionDetailsPage implements
053: IActionIOFilter, SelectionListener {
054:
055: public static final String DISPLAY_NAME = Messages
056: .getString("BIRTReportDetailsPage.UI_COMPONENT_NAME_BIRT"); //$NON-NLS-1$
057: public static final String[] BIRT_REPORT_TYPES = new String[] {
058: "html", "pdf" }; //$NON-NLS-1$ //$NON-NLS-2$ //TODO get this from BIRT
059:
060: ActionResourceText reportDefinition;
061: NewActionInputCombo reportFormat;
062: Section configurationSection;
063: ActionOutputText outputName;
064: ActionInputsList reportParams;
065: ActionInputsListToolbar reportParamsToolbar;
066: Button browseBtn;
067: IPath basePath;
068:
069: /**
070: * Creates a Birt report template.
071: */
072: public BIRTReportDetailsPage(IPath basePath) {
073: super ();
074: this .basePath = basePath;
075: }
076:
077: /* (non-Javadoc)
078: * @see org.pentaho.designstudio.editors.actionsequence.pages.actions.templates.ActionDefinitionTemplate#getComponentClassName()
079: */
080: public String getComponentName() {
081: return BirtReportAction.COMPONENT_NAME;
082: }
083:
084: /* (non-Javadoc)
085: * @see org.pentaho.designstudio.editors.actionsequence.pages.actions.templates.ActionDefinitionTemplate#getDisplayName()
086: */
087: public String getName() {
088: return DISPLAY_NAME;
089: }
090:
091: public void createDetailsComposite(Composite parent) {
092: Composite actionConfigComposite = parent;
093: GridLayout gridLayout = new GridLayout(2, true);
094: gridLayout.horizontalSpacing = 20;
095: actionConfigComposite.setLayout(gridLayout);
096:
097: WidgetFactory
098: .createLabel(
099: actionConfigComposite,
100: Messages
101: .getString("BirtReportDetailsPage.UI_REPORT_DEF_LABEL")); //$NON-NLS-1$
102:
103: Composite composite = WidgetFactory
104: .createComposite(actionConfigComposite);
105: gridLayout = new GridLayout(2, false);
106: gridLayout.marginWidth = 0;
107: gridLayout.marginHeight = 0;
108: composite.setLayout(gridLayout);
109: composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
110: WidgetFactory
111: .createLabel(
112: composite,
113: Messages
114: .getString("BirtReportDetailsPage.UI_REPORT_PARAMS_LABEL")); //$NON-NLS-1$
115:
116: GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
117: gridData.verticalAlignment = GridData.BEGINNING;
118: reportDefinition = new ActionResourceText(
119: actionConfigComposite, gridData);
120: reportDefinition.setBasePath(basePath);
121:
122: reportParams = new ActionInputsList(actionConfigComposite);
123: reportParams.setFilter(this );
124: gridData = new GridData(GridData.FILL_HORIZONTAL);
125: gridData.heightHint = 100;
126: gridData.verticalSpan = 7;
127: gridData.verticalAlignment = SWT.FILL;
128: reportParams.getList().setLayoutData(gridData);
129:
130: reportParamsToolbar = new ActionInputsListToolbar(composite,
131: reportParams);
132: gridData = new GridData(GridData.FILL_HORIZONTAL);
133: gridData.horizontalAlignment = GridData.END;
134: reportParamsToolbar.getControl().setLayoutData(gridData);
135:
136: browseBtn = WidgetFactory
137: .createButton(
138: actionConfigComposite,
139: Messages
140: .getString("JFreeReportDetailsPage.UI_BROWSE_LABEL"), SWT.FLAT); //$NON-NLS-1$
141: browseBtn.addSelectionListener(this );
142: gridData = new GridData(GridData.FILL_HORIZONTAL);
143: gridData.horizontalAlignment = GridData.END;
144: browseBtn.setLayoutData(gridData);
145:
146: WidgetFactory
147: .createLabel(
148: actionConfigComposite,
149: Messages
150: .getString("BirtReportDetailsPage.UI_OUTPUT_FPRMAT_LABEL")); //$NON-NLS-1$
151:
152: gridData = new GridData(GridData.FILL_HORIZONTAL);
153: reportFormat = new NewActionInputCombo(actionConfigComposite,
154: gridData);
155: reportFormat.setDefaultConstants(BIRT_REPORT_TYPES);
156:
157: WidgetFactory.createLabel(actionConfigComposite, ""); //$NON-NLS-1$
158:
159: WidgetFactory
160: .createLabel(
161: actionConfigComposite,
162: Messages
163: .getString("BirtReportDetailsPage.UI_OUTPUT_NAME_LABEL")); //$NON-NLS-1$
164:
165: gridData = new GridData(GridData.FILL_HORIZONTAL);
166: outputName = new ActionOutputText(actionConfigComposite,
167: gridData);
168: }
169:
170: public void refresh() {
171: super .refresh();
172: reportDefinition.setTargetResource(actionDefinition,
173: BirtReportAction.REPORT_DEFINITION_ELEMENT);
174: reportFormat.setTargetInput(actionDefinition,
175: BirtReportAction.OUTPUT_TYPE_ELEMENT,
176: ActionSequenceDocument.STRING_TYPE);
177: reportParams.setInput(actionDefinition);
178: reportParamsToolbar.refresh();
179:
180: outputName.setTargetOutput(actionDefinition,
181: BirtReportAction.OUTPUT_REPORT);
182: }
183:
184: public boolean accept(AbstractIOElement ioElement) {
185: boolean result = false;
186: if ((ioElement instanceof ActionSequenceInput)
187: || (ioElement instanceof ActionInput)) {
188: result = !ioElement.getName().equals(
189: BirtReportAction.OUTPUT_TYPE_ELEMENT);
190: } else if (ioElement instanceof ActionOutput) {
191: result = !((ActionOutput) ioElement).getPublicName()
192: .equals(BirtReportAction.OUTPUT_TYPE_ELEMENT);
193: }
194: return result;
195: }
196:
197: private void setResourcePath(String fileName, Text text) {
198: String fileSolution = SolutionHelper.getSolutionName(fileName);
199: Path filePath = new Path(fileName);
200: String baseSolution = SolutionHelper.getSolutionName(basePath
201: .toString());
202: String solutionRoot = SolutionHelper.getSolutionRoot(basePath
203: .toString());
204:
205: if ((baseSolution != null) && baseSolution.equals(fileSolution)) {
206: if (filePath.matchingFirstSegments(basePath) == basePath
207: .segmentCount()) {
208: IPath relativeFilePath = filePath
209: .removeFirstSegments(basePath.segmentCount());
210: text.setText(relativeFilePath.setDevice(
211: ActionSequenceResource.SOLUTION_SCHEME + ":")
212: .toString());
213: } else {
214: Path solutionPath = new Path(solutionRoot);
215: IPath relativePath = filePath
216: .removeFirstSegments(solutionPath
217: .segmentCount());
218: IPath absPath = relativePath.makeAbsolute().setDevice(
219: ActionSequenceResource.SOLUTION_SCHEME + ":"); //$NON-NLS-1$
220: text.setText(absPath.toString());
221: }
222: } else {
223: text.setText(ActionSequenceResource.FILE_SCHEME + ":"
224: + fileName);
225: }
226: }
227:
228: public boolean checkResourceReferences(
229: ActionDefinition actionDefinition) {
230: return (actionDefinition
231: .getResourceParam(BirtReportAction.REPORT_DEFINITION_ELEMENT) != null)
232: || (actionDefinition.getDocument().getResource(
233: BirtReportAction.REPORT_DEFINITION_ELEMENT) == null);
234: }
235:
236: public void fixResourceReferences(ActionDefinition actionDefinition) {
237: if ((actionDefinition
238: .getResourceParam(BirtReportAction.REPORT_DEFINITION_ELEMENT) == null)
239: && (actionDefinition.getDocument().getResource(
240: BirtReportAction.REPORT_DEFINITION_ELEMENT) != null)) {
241: actionDefinition
242: .addResourceParam(BirtReportAction.REPORT_DEFINITION_ELEMENT);
243: }
244: }
245:
246: public boolean accepts(IActionSequenceElement actionDef) {
247: return actionDef instanceof BirtReportAction;
248: }
249:
250: public void widgetDefaultSelected(SelectionEvent e) {
251: // TODO Auto-generated method stub
252:
253: }
254:
255: public void widgetSelected(SelectionEvent e) {
256: FileDialog fileChooser = new FileDialog(browseBtn.getShell(),
257: SWT.OPEN);
258: fileChooser
259: .setText(Messages
260: .getString("BIRTReportDetailsPage.SELECT_REPORT_DEFINITON")); //$NON-NLS-1$
261: fileChooser.setFilterExtensions(new String[] {
262: "*.rptdesign", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
263: fileChooser
264: .setFilterNames(new String[] {
265: Messages
266: .getString("BIRTReportDetailsPage.BIRT_REPORT_DEFINITION"), Messages.getString("BIRTReportDetailsPage.ALL_FILES") }); //$NON-NLS-1$ //$NON-NLS-2$
267: fileChooser.setFilterPath(basePath.toString());
268: String filename = fileChooser.open();
269: if (filename != null) {
270: setResourcePath(filename, (Text) reportDefinition
271: .getControl());
272: }
273: }
274: }
|