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.reportwizard;
014:
015: import java.io.File;
016: import java.io.IOException;
017: import java.net.URL;
018:
019: import org.eclipse.core.resources.IFile;
020: import org.eclipse.core.resources.IWorkspace;
021: import org.eclipse.core.resources.ResourcesPlugin;
022: import org.eclipse.core.runtime.CoreException;
023: import org.eclipse.core.runtime.IPath;
024: import org.eclipse.core.runtime.IProgressMonitor;
025: import org.eclipse.core.runtime.Platform;
026: import org.eclipse.jface.window.Window;
027: import org.eclipse.swt.layout.FillLayout;
028: import org.eclipse.swt.widgets.Composite;
029: import org.eclipse.swt.widgets.Shell;
030: import org.eclipse.ui.IEditorInput;
031: import org.eclipse.ui.IEditorPart;
032: import org.eclipse.ui.IEditorSite;
033: import org.eclipse.ui.IFileEditorInput;
034: import org.eclipse.ui.PartInitException;
035: import org.eclipse.ui.dialogs.SaveAsDialog;
036: import org.eclipse.ui.part.EditorPart;
037: import org.eclipse.ui.part.FileEditorInput;
038: import org.pentaho.designstudio.editors.reportwizard.preferences.PreferenceConstants;
039: import org.pentaho.jfreereport.wizard.ReportWizard;
040: import org.pentaho.jfreereport.wizard.ui.IDirtyListener;
041:
042: public class ReportDesignWizardEditor extends EditorPart {
043:
044: boolean isDirty;
045: ReportWizard reportWizard;
046:
047: public ReportDesignWizardEditor() {
048: super ();
049: // TODO Auto-generated constructor stub
050: }
051:
052: public void doSave(IProgressMonitor monitor) {
053: reportWizard.doSave();
054: isDirty = false;
055: firePropertyChange(PROP_DIRTY);
056: }
057:
058: public void doSaveAs() {
059: Shell shell = getSite().getShell();
060: IEditorInput input = getEditorInput();
061:
062: SaveAsDialog dialog = new SaveAsDialog(shell);
063:
064: IFile original = (input instanceof IFileEditorInput) ? ((IFileEditorInput) input)
065: .getFile()
066: : null;
067: if (original != null)
068: dialog.setOriginalFile(original);
069:
070: dialog.create();
071:
072: if (dialog.open() == Window.CANCEL) {
073: return;
074: }
075:
076: IPath filePath = dialog.getResult();
077: if (filePath == null) {
078: return;
079: }
080:
081: IWorkspace workspace = ResourcesPlugin.getWorkspace();
082: IFile file = workspace.getRoot().getFile(filePath);
083:
084: reportWizard.doSaveAs(file.getRawLocation().toString());
085: try {
086: file.refreshLocal(IFile.DEPTH_ZERO, null);
087: } catch (CoreException e) {
088: e.printStackTrace();
089: }
090: firePropertyChange(PROP_DIRTY);
091: isDirty = false;
092: setInput(new FileEditorInput(file));
093: setPartName(file.getName());
094: //Need to fire this because of a bug in windows
095: firePropertyChange(IEditorPart.PROP_INPUT);
096: }
097:
098: public void init(IEditorSite site, IEditorInput input)
099: throws PartInitException {
100: if (!(input instanceof IFileEditorInput))
101: throw new PartInitException(
102: "Invalid Input: Must be IFileEditorInput"); //$NON-NLS-1$
103: setSite(site);
104: setInput(input);
105: setPartName(input.getName());
106: }
107:
108: public boolean isDirty() {
109: return isDirty;
110: }
111:
112: public boolean isSaveAsAllowed() {
113: return true;
114: }
115:
116: public void createPartControl(Composite parent) {
117: parent.setLayout(new FillLayout());
118: // URL reportWizDir = ReportWizardPlugin.getDefault().getBundle().getEntry( "/rdw"); //$NON-NLS-1$
119: URL reportWizDir = ReportWizardPlugin.getDefault().getBundle()
120: .getEntry("/"); //$NON-NLS-1$
121: try {
122: reportWizDir = Platform.resolve(reportWizDir);
123: File reportWizardWorkingDir = new File(Platform.resolve(
124: reportWizDir).getPath());
125:
126: IFileEditorInput editorInput = (IFileEditorInput) getEditorInput();
127: try {
128: reportWizard = new ReportWizard(editorInput.getFile()
129: .getRawLocation().toString(), null,
130: reportWizardWorkingDir.getAbsolutePath(),
131: ReportWizardPlugin.getDefault()
132: .getStateLocation().toString(), null,
133: parent, ReportWizard.MODE_EMBEDDED);
134: } catch (Throwable e) {
135: e.printStackTrace();
136: }
137: String previewFormat = ReportWizardPlugin
138: .getDefault()
139: .getPluginPreferences()
140: .getString(
141: PreferenceConstants.DESIGN_WIZ_PREVIEW_FORMAT);
142: if ((previewFormat != null)
143: && (previewFormat.trim().length() > 0)) {
144: reportWizard.setPreviewType(previewFormat);
145: }
146: reportWizard.addDirtyListener(new IDirtyListener() {
147:
148: public void dirtyFired(boolean dirty) {
149: isDirty = dirty;
150: firePropertyChange(PROP_DIRTY);
151: }
152:
153: });
154: } catch (IOException e) {
155: e.printStackTrace();
156: }
157: }
158:
159: public void setFocus() {
160: // TODO Auto-generated method stub
161:
162: }
163:
164: }
|