View Javadoc

1   /*
2    * (C) Copyright 2006 Nuxeo SAS <http://nuxeo.com>
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the Eclipse Public License v1.0
6    * which accompanies this distribution, and is available at
7    * http://www.eclipse.org/legal/epl-v10.html
8    *
9    * Contributors:
10   *     Nuxeo - initial API and implementation
11   */
12  package org.eparapher.rcp.preferences;
13  
14  import org.apache.log4j.Logger;
15  import org.eclipse.jface.preference.BooleanFieldEditor;
16  import org.eclipse.jface.preference.DirectoryFieldEditor;
17  import org.eclipse.jface.preference.FieldEditorPreferencePage;
18  import org.eclipse.jface.preference.StringFieldEditor;
19  import org.eclipse.swt.SWT;
20  import org.eclipse.ui.IWorkbench;
21  import org.eclipse.ui.IWorkbenchPreferencePage;
22  import org.eparapher.core.EParapherManager;
23  import org.eparapher.core.tools.OODaemonManager;
24  import org.eparapher.rcp.Activator;
25  import org.eparapher.rcp.tools.RCPSettings;
26  
27  
28  public class OpenOfficeEditorPreferences extends FieldEditorPreferencePage implements
29  		IWorkbenchPreferencePage {
30  
31  
32  	public static final String ID = "org.eparapher.rcp.preferences.OpenOfficeEditorPreferences";
33  	
34  	private static Logger log = Logger.getLogger(OpenOfficeEditorPreferences.class);
35  	
36  	DirectoryFieldEditor localopenofficepath;
37  	DirectoryFieldEditor localopenofficebinarypath;
38  	StringFieldEditor    openofficeoptions;
39  	BooleanFieldEditor   startOOfficeAtStartup;
40  	
41  	public OpenOfficeEditorPreferences() {
42  		super(GRID);
43  		
44  		setPreferenceStore(Activator.getDefault().getPreferenceStore());
45  		setDescription("Configuration to (auto)launch OpenOffice.org");
46  	}
47  
48  	protected void createFieldEditors() {
49  		
50  		startOOfficeAtStartup = new BooleanFieldEditor(PreferenceConstants.P_LOCALOO_AUTOSTART,"&Start OpenOffice pdf converter at startup.", SWT.NONE, getFieldEditorParent());
51  		addField(startOOfficeAtStartup);
52  		
53  		localopenofficebinarypath = new DirectoryFieldEditor( PreferenceConstants.P_LOCALOOBINPATH, "&Open Office binary dir :", getFieldEditorParent());
54  		//String[] oofilefilter = {"soffice"};
55  		//localopenofficebinarypath.setFileExtensions(oofilefilter);
56  		addField(localopenofficebinarypath);
57  		
58  		localopenofficepath = new DirectoryFieldEditor( PreferenceConstants.P_LOCALOOLIBPATH, "&Open Office library dir :", getFieldEditorParent());
59  		addField(localopenofficepath);
60  		
61  		openofficeoptions = new StringFieldEditor( PreferenceConstants.P_LOCALOOOPTIONS, "&Open Office daemon parameters :", getFieldEditorParent());
62  		openofficeoptions.setEnabled(false, getFieldEditorParent());
63  		addField(openofficeoptions);
64  
65  		//openofficeoptions2 = new StringFieldEditor( PreferenceConstants.P_LOCALOOEDITOROPTIONS, "&Open Office Editor Daemon Options :", getFieldEditorParent());
66  		//openofficeoptions.setEnabled(false, getFieldEditorParent());
67  		//addField(openofficeoptions);
68  		
69  	}
70  
71  	public void init(IWorkbench workbench) {
72  	}
73      public boolean performOk() {
74      	
75      	//First, save properties
76      	boolean save = super.performOk();
77      	
78      	//TODO : verify if binary soffice or soffice.exe is in PreferenceConstants.P_LOCALOOBINPATH
79      	
80      	//TODO : restart OO if needed
81      	if (EParapherManager.getInstance().getSettings().isOpenOfficeAutostart()) {
82      		OODaemonManager.getInstance().stop();
83      	}
84      	
85          return save;
86      }
87  }