summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedricbosdo@openoffice.org>2011-01-04 21:22:11 +0100
committerCédric Bosdonnat <cedricbosdo@openoffice.org>2011-01-04 21:22:11 +0100
commitfa643d1adad92e29aad01d98996bcc7c5d8db702 (patch)
tree8d08980865f264b7cf85d049ad8367e2b224acf9
parent9d7b336d8e56f57b44529df134c102081b00ba66 (diff)
Added launch configuration shortcut for office launches
-rw-r--r--core/plugin.xml25
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/gui/PackageContentSelector.java35
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchShortcut.java196
-rw-r--r--core/source/org/openoffice/ide/eclipse/core/launch/office/PackageConfigTab.java4
4 files changed, 246 insertions, 14 deletions
diff --git a/core/plugin.xml b/core/plugin.xml
index 48000f7..11fab23 100644
--- a/core/plugin.xml
+++ b/core/plugin.xml
@@ -335,4 +335,29 @@
</action>
</objectContribution>
</extension>
+ <extension
+ point="org.eclipse.debug.ui.launchShortcuts">
+ <shortcut
+ class="org.openoffice.ide.eclipse.core.launch.office.OfficeLaunchShortcut"
+ icon="icons/libreoffice_16.png"
+ id="org.openoffice.ide.eclipse.core.launch.shortcut"
+ label="LibreOffice extension"
+ modes="run, debug">
+ <contextualLaunch>
+ <enablement>
+ <with variable="selection">
+ <count value="1" />
+ <iterate>
+ <and>
+ <adapt type="org.eclipse.core.resources.IProject" />
+ <test property="org.eclipse.debug.ui.projectNature"
+ value="org.openoffice.ide.eclipse.core.unonature" />
+ </and>
+ </iterate>
+ </with>
+ </enablement>
+ </contextualLaunch>
+ <configurationType id="org.openoffice.ide.eclipse.core.launchOpenOffice" />
+ </shortcut>
+ </extension>
</plugin>
diff --git a/core/source/org/openoffice/ide/eclipse/core/gui/PackageContentSelector.java b/core/source/org/openoffice/ide/eclipse/core/gui/PackageContentSelector.java
index 3271a16..a62dc4e 100644
--- a/core/source/org/openoffice/ide/eclipse/core/gui/PackageContentSelector.java
+++ b/core/source/org/openoffice/ide/eclipse/core/gui/PackageContentSelector.java
@@ -106,18 +106,7 @@ public class PackageContentSelector extends Composite {
* Populate the resource view with some default data (mainly the XCU / XCS files).
*/
public void loadDefaults( ) {
- // Select the XCU / XCS files by default
- IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject( mProject.getName() );
- FilesFinder finder = new FilesFinder(
- new String[] { IUnoidlProject.XCU_EXTENSION, IUnoidlProject.XCS_EXTENSION } );
- try {
- finder.addExclude( mProject.getDistFolder().getFullPath() );
- prj.accept( finder );
- } catch (CoreException e) {
- PluginLogger.error("Could not visit the project's content.", e);
- }
-
- ArrayList< IFile > files = finder.getResults();
+ List< IFile > files = getDefaultContent( mProject );
for (IFile file : files) {
mResourceGroup.initialCheckListItem( file );
mResourceGroup.initialCheckTreeItem( file );
@@ -143,6 +132,28 @@ public class PackageContentSelector extends Composite {
}
/**
+ * Get the default files to include in a package (mainly the XCU / XCS files).
+ *
+ * @param pUnoPrj the uno project to get the defaults from
+ *
+ * @return the list of the files to include by default
+ */
+ public static List<IFile> getDefaultContent( IUnoidlProject pUnoPrj ) {
+ // Select the XCU / XCS files by default
+ IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject( pUnoPrj.getName() );
+ FilesFinder finder = new FilesFinder(
+ new String[] { IUnoidlProject.XCU_EXTENSION, IUnoidlProject.XCS_EXTENSION } );
+ try {
+ finder.addExclude( pUnoPrj.getDistFolder().getFullPath() );
+ prj.accept( finder );
+ } catch (CoreException e) {
+ PluginLogger.error("Could not visit the project's content.", e);
+ }
+
+ return finder.getResults();
+ }
+
+ /**
* Convenience method to create and populate the UnoPackage.
*
* @param pProject the project to export
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchShortcut.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchShortcut.java
new file mode 100644
index 0000000..9728b56
--- /dev/null
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/OfficeLaunchShortcut.java
@@ -0,0 +1,196 @@
+/*************************************************************************
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright: 2010 by Cédric Bosdonnat
+ *
+ * All Rights Reserved.
+ *
+ ************************************************************************/
+package org.openoffice.ide.eclipse.core.launch.office;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.ui.CommonTab;
+import org.eclipse.debug.ui.DebugUITools;
+import org.eclipse.debug.ui.ILaunchShortcut;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.openoffice.ide.eclipse.core.PluginLogger;
+import org.openoffice.ide.eclipse.core.gui.PackageContentSelector;
+import org.openoffice.ide.eclipse.core.model.IUnoidlProject;
+import org.openoffice.ide.eclipse.core.model.ProjectsManager;
+
+/**
+ * Class launching the selected uno project as a LibreOffice extension.
+ *
+ * @author Cedric Bosdonnat
+ *
+ */
+public class OfficeLaunchShortcut implements ILaunchShortcut {
+
+ private static final String OFFICE_LAUNCH_CONFIG_ID =
+ "org.openoffice.ide.eclipse.core.launchOpenOffice"; //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ */
+ public void launch(ISelection pSelection, String pMode) {
+ if ( pSelection instanceof IStructuredSelection ) {
+ IStructuredSelection sel = ( IStructuredSelection ) pSelection;
+ Iterator<?> it = sel.iterator();
+
+ IUnoidlProject project = null;
+ while ( it.hasNext() && project == null) {
+ Object o = it.next();
+ if ( o instanceof IAdaptable ) {
+ IAdaptable adaptable = ( IAdaptable ) o;
+ IResource res = (IResource)adaptable.getAdapter( IResource.class );
+ if ( res != null ) {
+ project = ProjectsManager.getProject( res.getProject().getName() );
+ }
+ }
+ }
+
+ if ( project != null ) {
+ launch( project, pMode );
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void launch(IEditorPart pEditor, String pMode) {
+ IEditorInput input = pEditor.getEditorInput();
+ IFile file = ( IFile ) input.getAdapter( IFile.class );
+
+ if ( file != null ) {
+ IUnoidlProject prj = ProjectsManager.getProject( file.getProject().getName() );
+ if ( prj != null ) {
+ launch( prj, pMode );
+ }
+ }
+ }
+
+ /**
+ * Create a default launch configuration for the UNO project.
+ *
+ * @param pProject the UNO project for which to create the default launch config
+ * @return the newly created and saved launch configuration.
+ */
+ private ILaunchConfiguration createDefaultLaunchConfiguration( IUnoidlProject pProject ) {
+ ILaunchConfiguration created = null;
+ try {
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = launchManager.getLaunchConfigurationType( OFFICE_LAUNCH_CONFIG_ID );
+
+ String name = launchManager.generateUniqueLaunchConfigurationNameFrom( pProject.getName() );
+ ILaunchConfigurationWorkingCopy createdConfiguration = type.newInstance( null, name );
+
+ createdConfiguration.setAttribute( IOfficeLaunchConstants.PROJECT_NAME, pProject.getName() );
+ createdConfiguration.setAttribute( IOfficeLaunchConstants.CLEAN_USER_INSTALLATION, true );
+
+ List< IFile > content = PackageContentSelector.getDefaultContent( pProject );
+ String paths = new String();
+ for (IFile file : content) {
+ if ( !paths.isEmpty() ) {
+ paths += IOfficeLaunchConstants.PATHS_SEPARATOR;
+ }
+ paths += file.getProjectRelativePath().toString();
+ }
+ createdConfiguration.setAttribute( IOfficeLaunchConstants.CONTENT_PATHS, paths);
+
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject( pProject.getName() );
+ createdConfiguration.setMappedResources( new IResource[]{ project } );
+
+ // Common Tab Arguments
+ CommonTab tab = new CommonTab();
+ tab.setDefaults(createdConfiguration);
+ tab.dispose();
+
+ created = createdConfiguration.doSave();
+ } catch ( CoreException e ) {
+ PluginLogger.error( "Error creating the launch configuration", e );
+ created = null;
+ }
+
+ return created;
+ }
+
+ /**
+ * COPIED/MODIFIED from AntLaunchShortcut
+ * Returns a list of existing launch configuration for the given file.
+ *
+ * @param pProject the UNO project for which to look for existing launch configurations
+ * @return the list of the matching launch configurations
+ */
+ protected List< ILaunchConfiguration > findExistingLaunchConfigurations( IUnoidlProject pProject ) {
+ ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager.getLaunchConfigurationType( OFFICE_LAUNCH_CONFIG_ID );
+ List<ILaunchConfiguration> validConfigs = new ArrayList<ILaunchConfiguration>();
+ if (type != null) {
+ try {
+ ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
+
+ for ( int i = 0; i < configs.length; i++ ) {
+ String projectName = configs[i].getAttribute(IOfficeLaunchConstants.PROJECT_NAME, "");
+ if ( pProject.getName().equals( projectName ) ) {
+ validConfigs.add(configs[i]);
+ }
+ }
+ } catch (CoreException e) {
+ PluginLogger.error( "Unexpected error", e );
+ }
+ }
+ return validConfigs;
+ }
+
+ /**
+ * Launch a unoidl project using the default configuration.
+ *
+ * @param pProject the project to launch
+ * @param pMode the mode of the launch
+ */
+ private void launch(IUnoidlProject pProject, String pMode) {
+ ILaunchConfiguration conf = null;
+ List<ILaunchConfiguration> configurations = findExistingLaunchConfigurations( pProject );
+ if ( configurations.isEmpty( ) ) {
+ conf = createDefaultLaunchConfiguration( pProject );
+ } else {
+ conf = configurations.get( 0 );
+ }
+
+ if (conf != null ) {
+ DebugUITools.launch( conf, pMode );
+ }
+ }
+
+}
diff --git a/core/source/org/openoffice/ide/eclipse/core/launch/office/PackageConfigTab.java b/core/source/org/openoffice/ide/eclipse/core/launch/office/PackageConfigTab.java
index affe3c8..ba5eb98 100644
--- a/core/source/org/openoffice/ide/eclipse/core/launch/office/PackageConfigTab.java
+++ b/core/source/org/openoffice/ide/eclipse/core/launch/office/PackageConfigTab.java
@@ -79,7 +79,7 @@ public class PackageConfigTab extends AbstractLaunchConfigurationTab {
IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject( prjName );
String paths = pConfiguration.getAttribute( IOfficeLaunchConstants.CONTENT_PATHS, new String() );
- if(!paths.isEmpty()) {
+ if ( !paths.isEmpty() ) {
String[] pathsItems = paths.split( IOfficeLaunchConstants.PATHS_SEPARATOR );
for (String path : pathsItems) {
@@ -129,7 +129,7 @@ public class PackageConfigTab extends AbstractLaunchConfigurationTab {
String prjName = pConfiguration.getAttribute( IOfficeLaunchConstants.PROJECT_NAME, new String() );
IUnoidlProject project = ProjectsManager.getProject( prjName );
- if(null != project) {
+ if ( null != project ) {
mContentSelector.setProject( project );
List<IResource> selected = getResources( pConfiguration );