summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorcdan <cdan@savatech.ro>2010-06-14 17:33:03 +0300
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2010-06-16 11:43:24 +0200
commitd622c0ed05c86b67f6f7e2fc1f90b34f155a6fd4 (patch)
tree201abe01ac70c699611e1a27df6b9c85c0cc0187 /core
parente46154facef9afb40cddbdfa6b33182aef3884cb (diff)
First attempt of implementing an OpenOffice launch type.
Diffstat (limited to 'core')
-rwxr-xr-xcore/plugin.xml16
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/internal/model/AbstractOOo.java29
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/internal/model/messages.properties3
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/IOfficeLaunchConstants.java8
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/LaunchConfigurationTabs.java22
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/Messages.java20
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchDelegate.java68
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeTab.java156
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/messages.properties6
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/model/config/IOOo.java4
10 files changed, 331 insertions, 1 deletions
diff --git a/core/plugin.xml b/core/plugin.xml
index 4491ae0..f78f49a 100755
--- a/core/plugin.xml
+++ b/core/plugin.xml
@@ -263,6 +263,12 @@
id="org.openoffice.ide.eclipse.core.launchUreApplication"
modes="run"
name="URE Application"/>
+ <launchConfigurationType
+ delegate="org.openoffice.ide.eclipse.core.launch.office.OfficeLaunchDelegate"
+ id="org.openoffice.ide.eclipse.core.launchOpenOffice"
+ modes="run"
+ name="Open Office Application">
+ </launchConfigurationType>
</extension>
<extension
point="org.eclipse.debug.ui.launchConfigurationTabGroups">
@@ -270,6 +276,11 @@
class="org.openoffice.ide.eclipse.core.launch.LaunchConfigurationTabs"
id="org.openoffice.ide.eclipse.core.launchConfigurationTabGroup1"
type="org.openoffice.ide.eclipse.core.launchUreApplication"/>
+ <launchConfigurationTabGroup
+ class="org.openoffice.ide.eclipse.core.launch.office.LaunchConfigurationTabs"
+ id="org.openoffice.ide.eclipse.core.OfficeLlaunchConfigurationTabGroup1"
+ type="org.openoffice.ide.eclipse.core.launchOpenOffice">
+ </launchConfigurationTabGroup>
</extension>
<extension
point="org.eclipse.debug.ui.launchConfigurationTypeImages">
@@ -277,6 +288,11 @@
configTypeID="org.openoffice.ide.eclipse.core.launchUreApplication"
icon="icons/ure_app.gif"
id="org.openoffice.ide.eclipse.core.UreLaunchIcon"/>
+ <launchConfigurationTypeImage
+ configTypeID="org.openoffice.ide.eclipse.core.launchOpenOffice"
+ icon="icons/ooo16.png"
+ id="org.openoffice.ide.eclipse.core.OfficeLaunchIcon">
+ </launchConfigurationTypeImage>
</extension>
<extension
point="org.eclipse.ui.exportWizards">
diff --git a/core/source/org/openoffice/ide/eclipse/core/internal/model/AbstractOOo.java b/core/source/org/openoffice/ide/eclipse/core/internal/model/AbstractOOo.java
index 2c13d96..529551d 100644
--- a/core/source/org/openoffice/ide/eclipse/core/internal/model/AbstractOOo.java
+++ b/core/source/org/openoffice/ide/eclipse/core/internal/model/AbstractOOo.java
@@ -50,6 +50,7 @@ import java.io.StringWriter;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
@@ -361,6 +362,34 @@ public abstract class AbstractOOo implements IOOo, ITableElement {
DebugPlugin.newProcess(pLaunch, p, Messages.getString("AbstractOOo.UreProcessName") + pMain); //$NON-NLS-1$
}
+ public void runOpenOffice(IUnoidlProject pPrj,
+ ILaunch pLaunch, IPath userInstallation, IProgressMonitor pMonitor) {
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject( pPrj.getName() );
+ String[] env = pPrj.getLanguage().getLanguageBuidler().getBuildEnv(pPrj);
+
+ String pathSeparator = System.getProperty("path.separator");
+ String[] sPaths = pPrj.getOOo().getBinPath();
+ StringBuilder sPathValue = new StringBuilder();
+ for (String sPath : sPaths) {
+ sPathValue.append(sPath);
+ sPathValue.append(pathSeparator);
+ }
+
+ env = SystemHelper.addEnv(env, "PATH", sPathValue.toString(), pathSeparator);
+ if(null != userInstallation) {
+ env = SystemHelper.addEnv(env, "UserInstallation", userInstallation.toOSString(), null);
+ }
+
+ String command = "soffice.bin";
+// +
+// " -c " + pMain + //$NON-NLS-1$
+// " -l " + libpath + //$NON-NLS-1$
+// " -- " + pArgs; //$NON-NLS-1$
+
+ Process p = pPrj.getSdk().runToolWithEnv(prj, pPrj.getOOo(), command, env, pMonitor);
+ DebugPlugin.newProcess(pLaunch, p, Messages.getString("AbstractOOo.OpenOfficeProcessName")); //$NON-NLS-1$
+ }
+
/**
* Sets the target platform for tests.
*
diff --git a/core/source/org/openoffice/ide/eclipse/core/internal/model/messages.properties b/core/source/org/openoffice/ide/eclipse/core/internal/model/messages.properties
index 429b92d..5d99548 100644
--- a/core/source/org/openoffice/ide/eclipse/core/internal/model/messages.properties
+++ b/core/source/org/openoffice/ide/eclipse/core/internal/model/messages.properties
@@ -1,5 +1,6 @@
AbstractOOo.NoDirectoryError=Not an existing directory:
-AbstractOOo.UreProcessName=URE process :
+AbstractOOo.UreProcessName=URE process :
+AbstractOOo.OpenOfficeProcessName=OpenOffice
AbstractOOo.NoFileError=Not an existing file:
UnoidlProject.RemoveMarkerError=Failed to remove marker
UnoidlProject.NoOOoSdkError=No SDK or OOo set: won't build
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/IOfficeLaunchConstants.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/IOfficeLaunchConstants.java
new file mode 100644
index 0000000..153c548
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/IOfficeLaunchConstants.java
@@ -0,0 +1,8 @@
+package org.openoffice.ide.eclipse.core.launch.office;
+
+public interface IOfficeLaunchConstants {
+
+ String PROJECT_NAME = "project_name";
+ String CLEAN_USER_INSTALLATION = "useCleanUserInstallation";
+
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/LaunchConfigurationTabs.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/LaunchConfigurationTabs.java
new file mode 100644
index 0000000..c6789b2
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/LaunchConfigurationTabs.java
@@ -0,0 +1,22 @@
+package org.openoffice.ide.eclipse.core.launch.office;
+
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTabGroup;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.ILaunchConfigurationDialog;
+import org.eclipse.debug.ui.ILaunchConfigurationTab;
+
+public class LaunchConfigurationTabs extends
+ AbstractLaunchConfigurationTabGroup {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void createTabs(ILaunchConfigurationDialog pDialog, String pMode) {
+ ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] {
+ new OfficeTab(), new CommonTab() };
+
+ setTabs(tabs);
+
+ }
+
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/Messages.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/Messages.java
new file mode 100644
index 0000000..ac9c276
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/Messages.java
@@ -0,0 +1,20 @@
+package org.openoffice.ide.eclipse.core.launch.office;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.openoffice.ide.eclipse.core.launch.office.messages"; //$NON-NLS-1$
+ public static String OfficeTab_Options;
+ public static String OfficeTab_Configurationerror;
+ public static String OfficeTab_ProjectNameLabel;
+ public static String OfficeTab_Title;
+ public static String OfficeTab_UnoProject;
+ public static String OfficeTab_ChkUseCleanUserInstallation;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchDelegate.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchDelegate.java
new file mode 100644
index 0000000..fbfaecb
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchDelegate.java
@@ -0,0 +1,68 @@
+package org.openoffice.ide.eclipse.core.launch.office;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
+import org.openoffice.ide.eclipse.core.model.ProjectsManager;
+
+public class OfficeLaunchDelegate extends LaunchConfigurationDelegate {
+
+ /**
+ * Export the .oxt file, deploy it in openoffice, run openoffice.
+ */
+ private static final int TASK_UNITS = 3;
+
+ /**
+ * {@inheritDoc}
+ */
+ public void launch(ILaunchConfiguration pConfiguration, String pMode,
+ ILaunch pLaunch, IProgressMonitor pMonitor) throws CoreException {
+ if (pMonitor == null) {
+ pMonitor = new NullProgressMonitor();
+ }
+
+ try {
+ pMonitor.beginTask(MessageFormat.format("{0}...", //$NON-NLS-1$
+ new Object[] { pConfiguration.getName() }), TASK_UNITS);
+ // check for cancellation
+ if (pMonitor.isCanceled()) {
+ return;
+ }
+
+ String prjName = pConfiguration.getAttribute(
+ IOfficeLaunchConstants.PROJECT_NAME, ""); //$NON-NLS-1$
+ IUnoidlProject prj = ProjectsManager.getProject(prjName);
+
+ if (null != prj) {
+ try {
+ // ILanguageBuilder langBuilder = prj.getLanguage()
+ // .getLanguageBuidler();
+ // langBuilder.createLibrary(prj);
+
+ // Run an OpenOffice instance
+ prj.getOOo().runOpenOffice(prj, pLaunch, null, pMonitor);
+ } catch (Exception e) {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ public void run() {
+ MessageDialog.openError(Display.getDefault()
+ .getActiveShell(), "Error Title", //$NON-NLS-1$
+ "Error Message"); //$NON-NLS-1$
+ }
+ });
+ }
+ }
+ } finally {
+ pMonitor.done();
+ }
+ }
+
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeTab.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeTab.java
new file mode 100644
index 0000000..ae5710e
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeTab.java
@@ -0,0 +1,156 @@
+package org.openoffice.ide.eclipse.core.launch.office;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+import org.openoffice.ide.eclipse.core.PluginLogger;
+import org.openoffice.ide.eclipse.core.gui.UnoProjectLabelProvider;
+import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
+import org.openoffice.ide.eclipse.core.model.ProjectsManager;
+
+public class OfficeTab extends AbstractLaunchConfigurationTab {
+
+ private static final int LAYOUT_COLUMNS = 3;
+ private Text mProjectTxt;
+ private Button mProjectBtn;
+ private Button useCleanUserInstallation;
+ private SelectionListener mListener = new ChangeListener();
+
+ public void createControl(Composite pParent) {
+ Composite comp = new Composite(pParent, SWT.NONE);
+ comp.setLayoutData(new GridData(GridData.FILL_BOTH));
+ comp.setLayout(new GridLayout());
+
+ createProjectGroup(comp);
+
+ createOptionsGroup(comp);
+
+ setControl(comp);
+ }
+
+ private void createOptionsGroup(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText(Messages.OfficeTab_Options);
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ useCleanUserInstallation = new Button(group, SWT.CHECK);
+ useCleanUserInstallation
+ .setText(Messages.OfficeTab_ChkUseCleanUserInstallation);
+ useCleanUserInstallation.addSelectionListener(mListener);
+ }
+
+ private void createProjectGroup(Composite parent) {
+ Group group = new Group(parent, SWT.NONE);
+ group.setText(Messages.OfficeTab_UnoProject);
+ group.setLayout(new GridLayout());
+ group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Composite field = new Composite(group, SWT.NONE);
+ field.setLayout(new GridLayout(LAYOUT_COLUMNS, false));
+ field.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ Label lbl = new Label(field, SWT.NONE);
+ lbl.setText(Messages.OfficeTab_ProjectNameLabel);
+ lbl.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
+
+ mProjectTxt = new Text(field, SWT.SINGLE | SWT.BORDER);
+ mProjectTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
+ | GridData.GRAB_HORIZONTAL));
+ // mProjectTxt.addModifyListener(mListener);
+
+ mProjectBtn = new Button(field, SWT.PUSH);
+ mProjectBtn.setText("...");
+ mProjectBtn.addSelectionListener(mListener);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getName() {
+ return Messages.OfficeTab_Title;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void initializeFrom(ILaunchConfiguration pConfiguration) {
+ try {
+ mProjectTxt.setText(pConfiguration.getAttribute(
+ IOfficeLaunchConstants.PROJECT_NAME, ""));
+ useCleanUserInstallation.setSelection(pConfiguration.getAttribute(
+ IOfficeLaunchConstants.CLEAN_USER_INSTALLATION, false));
+ } catch (CoreException e) {
+ PluginLogger.error(Messages.OfficeTab_Configurationerror, e);
+ }
+ }
+
+ public void performApply(ILaunchConfigurationWorkingCopy pConfiguration) {
+ pConfiguration.setAttribute(IOfficeLaunchConstants.PROJECT_NAME,
+ mProjectTxt.getText().trim());
+ pConfiguration.setAttribute(
+ IOfficeLaunchConstants.CLEAN_USER_INSTALLATION,
+ useCleanUserInstallation.getSelection());
+ }
+
+ public void setDefaults(ILaunchConfigurationWorkingCopy pConfiguration) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean isValid(ILaunchConfiguration pLaunchConfig) {
+ boolean valid = false;
+
+ try {
+
+ boolean projectSet = !pLaunchConfig.getAttribute(
+ IOfficeLaunchConstants.PROJECT_NAME, "").equals("");//$NON-NLS-1$ //$NON-NLS-2$
+ if (projectSet) {
+ String name = pLaunchConfig.getAttribute(
+ IOfficeLaunchConstants.PROJECT_NAME, ""); //$NON-NLS-1$
+ valid = ProjectsManager.getProject(name) != null;
+ }
+ } catch (CoreException e) {
+ PluginLogger.error(Messages.OfficeTab_Configurationerror, e);
+ }
+
+ return valid;
+ }
+
+ private class ChangeListener extends SelectionAdapter {
+ public void widgetSelected(SelectionEvent event) {
+ if (event.getSource().equals(mProjectBtn)) {
+ ILabelProvider labelProvider = new UnoProjectLabelProvider();
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(
+ getShell(), labelProvider);
+ dialog.setTitle("ProjectChooserTitle"); //$NON-NLS-1$
+ dialog.setMessage("ProjectChooserMessage"); //$NON-NLS-1$
+ dialog.setElements(ProjectsManager.getProjects());
+
+ if (dialog.open() == Window.OK) {
+ IUnoidlProject mProject = (IUnoidlProject) dialog
+ .getFirstResult();
+ mProjectTxt.setText(mProject.getName());
+ }
+ }
+ setDirty(true);
+ getLaunchConfigurationDialog().updateButtons();
+ }
+ }
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/messages.properties b/core/source/org/openoffice/ide/eclipse/core/launch/office/messages.properties
new file mode 100644
index 0000000..f558447
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/messages.properties
@@ -0,0 +1,6 @@
+OfficeTab_Configurationerror=Configuration Error
+OfficeTab_ProjectNameLabel=Project
+OfficeTab_Title=OpenOffice
+OfficeTab_UnoProject=UNO Project
+OfficeTab_Options=Options
+OfficeTab_ChkUseCleanUserInstallation=Use Clean User Installation \ No newline at end of file
diff --git a/core/source/org/openoffice/ide/eclipse/core/model/config/IOOo.java b/core/source/org/openoffice/ide/eclipse/core/model/config/IOOo.java
index 3c0385d..5ff7004 100644
--- a/core/source/org/openoffice/ide/eclipse/core/model/config/IOOo.java
+++ b/core/source/org/openoffice/ide/eclipse/core/model/config/IOOo.java
@@ -45,6 +45,7 @@ package org.openoffice.ide.eclipse.core.model.config;
import java.io.File;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.debug.core.ILaunch;
import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
@@ -163,6 +164,9 @@ public interface IOOo {
public void runUno(IUnoidlProject pPrj, String pMain, String pArgs,
ILaunch pLaunch, IProgressMonitor pMonitor);
+ public void runOpenOffice(IUnoidlProject pPrj,
+ ILaunch pLaunch, IPath userInstallation, IProgressMonitor pMonitor);
+
/**
* @return <code>true</code> if the OOo instance has a package manager.
*/