Author: dgolovin
Date: 2007-09-18 15:44:52 -0400 (Tue, 18 Sep 2007)
New Revision: 3698
Added:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/WorkbenchUtils.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-848
Copied:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
(from rev 3673,
trunk/tests/tests/org.jboss.tools.test/src/org/jboss/tools/test/util/ResourcesUtils.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/ResourcesUtils.java 2007-09-18
19:44:52 UTC (rev 3698)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Arrays;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
+import org.eclipse.ui.wizards.datatransfer.ImportOperation;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author eskimo
+ *
+ */
+public class ResourcesUtils {
+
+ public static IProject importProject(Bundle bundle, String templLocation,
+ IProgressMonitor monitor) throws IOException, CoreException,
+ InvocationTargetException, InterruptedException {
+
+ String tplPrjLcStr;
+ tplPrjLcStr = FileLocator.resolve(bundle.getEntry(templLocation))
+ .getFile();
+
+ return importProject(tplPrjLcStr, monitor);
+ }
+
+ public static IProject importProject(String location,
+ IProgressMonitor monitor) throws CoreException, IOException,
+ InvocationTargetException, InterruptedException {
+ IProject importedPrj = createEclipseProjectDromDescriptor(location,
+ monitor);
+ ImportOperation op = new ImportOperation(importedPrj.getFullPath(),
+ new File(location), FileSystemStructureProvider.INSTANCE,
+ new IOverwriteQuery() {
+ public String queryOverwrite(String pathString) {
+ return IOverwriteQuery.ALL;
+ }
+ }, Arrays.asList(new File(location).listFiles()));
+
+ op.setCreateContainerStructure(false);
+ op.run(monitor);
+ return importedPrj;
+ }
+
+ public static IProject createEclipseProject(String projectName,
+ IProgressMonitor monitor) throws CoreException {
+
+ IProject newProjectHandle = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ final IProjectDescription description = workspace
+ .newProjectDescription(projectName);
+ newProjectHandle.create(description, new NullProgressMonitor());
+ newProjectHandle.open(monitor);
+ return newProjectHandle;
+ }
+
+ public static IProject createEclipseProjectDromDescriptor(
+ String templateLocation, IProgressMonitor monitor)
+ throws CoreException, IOException {
+
+ IPath tplPrjDescr = new Path(templateLocation)
+ .append(IProjectDescription.DESCRIPTION_FILE_NAME);
+ IProjectDescription descr = ResourcesPlugin.getWorkspace()
+ .loadProjectDescription(tplPrjDescr);
+ descr.setLocation(null);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
+ descr.getName());
+ project.create(descr, monitor);
+ project.open(IResource.BACKGROUND_REFRESH, monitor);
+
+ return project;
+ }
+}
Copied:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/WorkbenchUtils.java
(from rev 3673,
trunk/tests/tests/org.jboss.tools.test/src/org/jboss/tools/test/util/WorkbenchUtils.java)
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/WorkbenchUtils.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/WorkbenchUtils.java 2007-09-18
19:44:52 UTC (rev 3698)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.util;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.wizards.IWizardDescriptor;
+import org.jboss.tools.common.CommonPlugin;
+
+/**
+ * @author eskimo
+ *
+ */
+public class WorkbenchUtils {
+
+ static public IWizard findWizardByDefId(String definitionId) {
+ IWizardDescriptor aWizardDescr =
+ getWorkbench().getNewWizardRegistry()
+ .findWizard(definitionId);
+ IWorkbenchWizard aWizard=null;
+ try {
+ aWizard = aWizardDescr.createWizard();
+ } catch (CoreException e) {
+ CommonPlugin.getPluginLog().logError("Cannot create IWorkbenchWizard
instance",e);
+ }
+ return aWizard;
+ }
+
+ public static IWorkbench getWorkbench() {
+ return PlatformUI.getWorkbench();
+ }
+
+ /**
+ * @return
+ */
+ public static IWorkbenchPage getWorkbenchActivePage() {
+ // TODO Auto-generated method stub
+ return getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ }
+}