From c45acf1a1178e5492db5f4b37e931f291ca86625 Mon Sep 17 00:00:00 2001 From: Vladislav Kaznacheev Date: Wed, 23 May 2007 17:33:30 +0400 Subject: [PATCH] Generalized Import actions --- resources/src/idea/ActionManager.xml | 5 +- .../src/messages/ActionsBundle.properties | 1 + .../src/messages/ProjectBundle.properties | 2 + resources_eng/src/messages/UIBundle.properties | 4 + .../projectImport/ProjectImportProvider.java | 16 +++ .../projectImport/ProjectImportWizard.java | 87 +++++++++++++++++ .../wm/impl/welcomeScreen/GetFromVcsAction.java | 105 +++++--------------- .../impl/welcomeScreen/RecentProjectsAction.java | 107 ++++++--------------- ...tFromVcsAction.java => WelcomePopupAction.java} | 35 +++---- .../wm/impl/welcomeScreen/WelcomeScreen.java | 24 ++--- 10 files changed, 196 insertions(+), 190 deletions(-) create mode 100644 source/com/intellij/projectImport/ProjectImportProvider.java create mode 100644 source/com/intellij/projectImport/ProjectImportWizard.java rewrite ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java (83%) rewrite ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/RecentProjectsAction.java (78%) copy ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/{GetFromVcsAction.java => WelcomePopupAction.java} (60%) diff --git a/resources/src/idea/ActionManager.xml b/resources/src/idea/ActionManager.xml index dffb9cefc9..f761c538e3 100644 --- a/resources/src/idea/ActionManager.xml +++ b/resources/src/idea/ActionManager.xml @@ -210,6 +210,8 @@ + + @@ -230,8 +232,7 @@ - - + diff --git a/resources_eng/src/messages/ActionsBundle.properties b/resources_eng/src/messages/ActionsBundle.properties index 30d69c3001..153300873f 100644 --- a/resources_eng/src/messages/ActionsBundle.properties +++ b/resources_eng/src/messages/ActionsBundle.properties @@ -195,6 +195,7 @@ action.Vcs.MarkSourcesAsCurrent.description=Mark sources as up-to-date group.VcsGroup.text=Version Control group.VcsFileGroupPopup.text=Version Control Group group.FileMenu.text=_File +group.ProjectImport.text=Import _Projects action.NewProject.text=_New Project... action.NewProject.description=Create a new project action.NewModule.text=New _Module... diff --git a/resources_eng/src/messages/ProjectBundle.properties b/resources_eng/src/messages/ProjectBundle.properties index e1f3673c48..0115a1d460 100644 --- a/resources_eng/src/messages/ProjectBundle.properties +++ b/resources_eng/src/messages/ProjectBundle.properties @@ -38,6 +38,8 @@ project.import.eclipse.file.invalid.path=Invalid Path project.import.eclipse.show.settings=Open Module Properties after import project.import.eclipse.project=Eclipse project to import: project.import.eclipse.home=Eclipse Home: + +project.import.jbuilder.name=JBuilder project.import.jbuilder.not.found=Project to import not found project.import.jbuilder.not.found.title=Nothing Found To Import project.import.jbuilder.module.creation.cancelled=Creation of module was cancelled by component: {0}\nReason is: {1} diff --git a/resources_eng/src/messages/UIBundle.properties b/resources_eng/src/messages/UIBundle.properties index a217493b22..ea166f0ea6 100644 --- a/resources_eng/src/messages/UIBundle.properties +++ b/resources_eng/src/messages/UIBundle.properties @@ -84,6 +84,10 @@ popup.hints.panel.click.to.configure.profile.text=Click to configure inspection read.only.attr.panel.double.click.to.toggle.attr.tooltip.text=Double-click to toggle the read-only attribute welcome.screen.get.from.vcs.action.no.vcs.plugins.with.check.out.action.installed.action.name=No VCS plugins with Check-out action installed. welcome.screen.get.from.vcs.action.checkout.from.list.popup.title=Checkout from +welcome.screen.import.projects.action.name=Import Projects +welcome.screen.import.projects.action.description=You can import projects created with other tools. Click the icon or link to select a project type. +welcome.screen.import.projects.action.popup.title=Import from +welcome.screen.import.projects.action.no.importers.installed.action.name=No plugins with Import Projects action installed welcome.screen.recent.projects.action.no.recent.projects.to.display.action.name=No recent projects to display. welcome.screen.quick.start.action.group.name=Quick Start welcome.screen.documentation.action.group.name=Documentation diff --git a/source/com/intellij/projectImport/ProjectImportProvider.java b/source/com/intellij/projectImport/ProjectImportProvider.java new file mode 100644 index 0000000000..a0b0e9ee76 --- /dev/null +++ b/source/com/intellij/projectImport/ProjectImportProvider.java @@ -0,0 +1,16 @@ +package com.intellij.projectImport; + +import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NonNls; + +/** + * @author Vladislav.Kaznacheev + */ +public interface ProjectImportProvider { + @NonNls ExtensionPointName EXTENSION_POINT_NAME = new ExtensionPointName("com.intellij.projectImportProvider"); + + String getName(); + + void doImport(Project currentProject); +} diff --git a/source/com/intellij/projectImport/ProjectImportWizard.java b/source/com/intellij/projectImport/ProjectImportWizard.java new file mode 100644 index 0000000000..2ea616ae18 --- /dev/null +++ b/source/com/intellij/projectImport/ProjectImportWizard.java @@ -0,0 +1,87 @@ +package com.intellij.projectImport; + +import com.intellij.CommonBundle; +import com.intellij.ide.IdeBundle; +import com.intellij.ide.impl.ProjectUtil; +import com.intellij.ide.util.projectWizard.AddModuleWizard; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.project.ex.ProjectManagerEx; +import com.intellij.openapi.projectRoots.ProjectJdk; +import com.intellij.openapi.roots.ex.ProjectRootManagerEx; +import com.intellij.openapi.ui.Messages; +import com.intellij.projectImport.eclipse.action.EclipseProjectImporter; + +/** + * @author Vladislav.Kaznacheev + */ +public abstract class ProjectImportWizard implements ProjectImportProvider { + + public void doImport(final Project currentProject) { + final String title = getTitle(); + + final String[] options = new String[]{IdeBundle.message("project.import.into.new.project"), + IdeBundle.message("project.import.into.existing.project"), CommonBundle.getCancelButtonText()}; + int ret = currentProject == null + ? 0 + : Messages.showDialog(IdeBundle.message("project.import.destination"), title, options, 0, Messages.getQuestionIcon()); + + if (ret == 2 || ret == -1) { // Cancel clicked or Esc pressed + return; + } + + final boolean updateCurrent = ret != 0; + + final AddModuleWizard dialog = new AddModuleWizard(title, getStepsFactory(currentProject, updateCurrent), !updateCurrent); + dialog.show(); + if (!dialog.isOK()) { + return; + } + + final Project projectToUpdate = + updateCurrent ? currentProject : ProjectManagerEx.getInstanceEx().newProject(dialog.getNewProjectFilePath(), true, false); + + if (!initImport(currentProject, projectToUpdate)) { + return; + } + + if (!updateCurrent) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + setProjectParameters(projectToUpdate, dialog.getNewProjectJdk(), dialog.getNewCompileOutput()); + } + }); + ProjectUtil.closePreviousProject(currentProject); + ProjectUtil.updateLastProjectLocation(dialog.getNewProjectFilePath()); + ProjectManagerEx.getInstanceEx().openProject(projectToUpdate); + } + + commitImport(projectToUpdate); + } + + protected String getTitle() { + return IdeBundle.message("project.import.wizard.title", getName()); + } + + private static void setProjectParameters(final Project project, final ProjectJdk jdk, final String compilerOutput) { + final ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project); + + if (jdk != null) { + final String versionString = jdk.getVersionString(); + if (versionString != null) { + rootManager.setProjectJdk(jdk); + rootManager.setLanguageLevel(ProjectUtil.getDefaultLanguageLevel(versionString)); + } + } + + rootManager.setCompilerOutputUrl(EclipseProjectImporter.getUrl(compilerOutput)); + } + + protected abstract AddModuleWizard.ExtraStepsCreator getStepsFactory(final Project currentProject, final boolean updateCurrent); + + protected boolean initImport(final Project currentProject, final Project dstProject) { + return true; + } + + protected abstract void commitImport(final Project project); +} diff --git a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java dissimilarity index 83% index a258414524..ce308932e7 100644 --- a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java +++ b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java @@ -1,80 +1,25 @@ -package com.intellij.openapi.wm.impl.welcomeScreen; - -import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.openapi.vcs.CheckoutProvider; -import com.intellij.openapi.vcs.checkout.CheckoutAction; -import com.intellij.openapi.wm.ex.WindowManagerEx; -import com.intellij.ui.UIBundle; - -import javax.swing.*; -import java.awt.*; -import java.awt.event.InputEvent; - -public class GetFromVcsAction{ - - protected void fillActions(Project project, DefaultActionGroup group) { - final CheckoutProvider[] providers = Extensions.getExtensions(CheckoutProvider.EXTENSION_POINT_NAME); - for (CheckoutProvider provider : providers) { - group.add(new CheckoutAction(provider)); - } - } - - public void actionPerformed(Component contextComponent, final InputEvent e) { - final DefaultActionGroup group = new DefaultActionGroup(); - fillActions(null, group); - - if (group.getChildrenCount() == 0) { - group.add(new AnAction( - UIBundle.message("welcome.screen.get.from.vcs.action.no.vcs.plugins.with.check.out.action.installed.action.name")) { - public void actionPerformed(AnActionEvent e) { - group.setPopup(false); - } - } ); - } - - final ListPopup popup = JBPopupFactory.getInstance() - .createActionGroupPopup(UIBundle.message("welcome.screen.get.from.vcs.action.checkout.from.list.popup.title"), - group, - createDataContext(contextComponent), - JBPopupFactory.ActionSelectionAid.NUMBERING, - true); - - - Component focusedComponent = e.getComponent(); - if (focusedComponent != null) { - popup.showUnderneathOf(focusedComponent); - } - else { - Rectangle r; - int x; - int y; - focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent((Project)null); - r = WindowManagerEx.getInstanceEx().getScreenBounds(); - x = r.x + r.width / 2; - y = r.y + r.height / 2; - Point point = new Point(x, y); - SwingUtilities.convertPointToScreen(point, focusedComponent.getParent()); - - popup.showInScreenCoordinates(focusedComponent.getParent(), point); - } - } - - private DataContext createDataContext(final Component contextComponent) { - return new DataContext() { - public Object getData(String dataId) { - if (DataConstants.PROJECT.equals(dataId)) { - return null; - } - return contextComponent; - } - }; - } - - protected boolean isEnabled() { - return true; //To change body of implemented methods use File | Settings | File Templates. - } -} +package com.intellij.openapi.wm.impl.welcomeScreen; + +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.vcs.CheckoutProvider; +import com.intellij.openapi.vcs.checkout.CheckoutAction; +import com.intellij.ui.UIBundle; + +public class GetFromVcsAction extends WelcomePopupAction{ + + protected void fillActions(DefaultActionGroup group) { + final CheckoutProvider[] providers = Extensions.getExtensions(CheckoutProvider.EXTENSION_POINT_NAME); + for (CheckoutProvider provider : providers) { + group.add(new CheckoutAction(provider)); + } + } + + protected String getCaption() { + return UIBundle.message("welcome.screen.get.from.vcs.action.checkout.from.list.popup.title"); + } + + protected String getTextForEmpty() { + return UIBundle.message("welcome.screen.get.from.vcs.action.no.vcs.plugins.with.check.out.action.installed.action.name"); + } +} diff --git a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/RecentProjectsAction.java b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/RecentProjectsAction.java dissimilarity index 78% index 71fc7d0cbb..787d2b6b44 100644 --- a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/RecentProjectsAction.java +++ b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/RecentProjectsAction.java @@ -1,76 +1,31 @@ -package com.intellij.openapi.wm.impl.welcomeScreen; - -import com.intellij.ide.RecentProjectsManager; -import com.intellij.ide.actions.QuickSwitchSchemeAction; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.openapi.wm.ex.WindowManagerEx; -import com.intellij.ui.UIBundle; - -import javax.swing.*; -import java.awt.*; - -/** - * Created by IntelliJ IDEA. - * User: pti - * Date: Mar 2, 2005 - * Time: 4:02:31 PM - * To change this template use File | Settings | File Templates. - */ -public class RecentProjectsAction extends QuickSwitchSchemeAction { - - protected void fillActions(Project project, final DefaultActionGroup group) { - final AnAction[] recentProjectActions = RecentProjectsManager.getInstance().getRecentProjectsActions(false); - if (recentProjectActions == null || recentProjectActions.length == 0) { - AnAction action = new AnAction(UIBundle.message("welcome.screen.recent.projects.action.no.recent.projects.to.display.action.name")) { - public void actionPerformed(AnActionEvent e) { - group.setPopup(false); - } - }; - group.add(action); - } - else { - for (AnAction action : recentProjectActions) { - group.add(action); - } - } - } - - public void actionPerformed(AnActionEvent e) { - DefaultActionGroup group = new DefaultActionGroup(); - fillActions(null, group); - - final ListPopup popup = JBPopupFactory.getInstance() - .createActionGroupPopup(e.getPresentation().getText(), - group, - e.getDataContext(), - JBPopupFactory.ActionSelectionAid.NUMBERING, - true); - - Component focusedComponent = e.getInputEvent().getComponent(); - if (focusedComponent != null) { - popup.showUnderneathOf(focusedComponent); - } - else { - Rectangle r; - int x; - int y; - focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent((Project)null); - r = WindowManagerEx.getInstanceEx().getScreenBounds(); - x = r.x + r.width / 2; - y = r.y + r.height / 2; - Point point = new Point(x, y); - SwingUtilities.convertPointToScreen(point, focusedComponent.getParent()); - - popup.showInScreenCoordinates(focusedComponent.getParent(), point); - } - } - - protected boolean isEnabled() { - return true; - } -} +package com.intellij.openapi.wm.impl.welcomeScreen; + +import com.intellij.ide.RecentProjectsManager; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.ui.UIBundle; + +/** + * Created by IntelliJ IDEA. + * User: pti + * Date: Mar 2, 2005 + * Time: 4:02:31 PM + * To change this template use File | Settings | File Templates. + */ +public class RecentProjectsAction extends WelcomePopupAction/*extends QuickSwitchSchemeAction*/ { + + protected void fillActions(final DefaultActionGroup group) { + final AnAction[] recentProjectActions = RecentProjectsManager.getInstance().getRecentProjectsActions(false); + for (AnAction action : recentProjectActions) { + group.add(action); + } + } + + protected String getTextForEmpty() { + return UIBundle.message("welcome.screen.recent.projects.action.no.recent.projects.to.display.action.name"); + } + + protected String getCaption() { + return ""; + } +} diff --git a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomePopupAction.java similarity index 60% copy from ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java copy to ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomePopupAction.java index a258414524..9859538f77 100644 --- a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/GetFromVcsAction.java +++ b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomePopupAction.java @@ -1,35 +1,32 @@ package com.intellij.openapi.wm.impl.welcomeScreen; import com.intellij.openapi.actionSystem.*; -import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; -import com.intellij.openapi.vcs.CheckoutProvider; -import com.intellij.openapi.vcs.checkout.CheckoutAction; import com.intellij.openapi.wm.ex.WindowManagerEx; -import com.intellij.ui.UIBundle; import javax.swing.*; import java.awt.*; import java.awt.event.InputEvent; -public class GetFromVcsAction{ +/** + * @author Vladislav.Kaznacheev + */ +public abstract class WelcomePopupAction { - protected void fillActions(Project project, DefaultActionGroup group) { - final CheckoutProvider[] providers = Extensions.getExtensions(CheckoutProvider.EXTENSION_POINT_NAME); - for (CheckoutProvider provider : providers) { - group.add(new CheckoutAction(provider)); - } - } + protected abstract void fillActions(DefaultActionGroup group); + + protected abstract String getTextForEmpty(); - public void actionPerformed(Component contextComponent, final InputEvent e) { + protected abstract String getCaption(); + + public void showPopup(Component contextComponent, final InputEvent e) { final DefaultActionGroup group = new DefaultActionGroup(); - fillActions(null, group); + fillActions(group); if (group.getChildrenCount() == 0) { - group.add(new AnAction( - UIBundle.message("welcome.screen.get.from.vcs.action.no.vcs.plugins.with.check.out.action.installed.action.name")) { + group.add(new AnAction(getTextForEmpty()) { public void actionPerformed(AnActionEvent e) { group.setPopup(false); } @@ -37,7 +34,7 @@ public class GetFromVcsAction{ } final ListPopup popup = JBPopupFactory.getInstance() - .createActionGroupPopup(UIBundle.message("welcome.screen.get.from.vcs.action.checkout.from.list.popup.title"), + .createActionGroupPopup(getCaption(), group, createDataContext(contextComponent), JBPopupFactory.ActionSelectionAid.NUMBERING, @@ -63,7 +60,7 @@ public class GetFromVcsAction{ } } - private DataContext createDataContext(final Component contextComponent) { + private static DataContext createDataContext(final Component contextComponent) { return new DataContext() { public Object getData(String dataId) { if (DataConstants.PROJECT.equals(dataId)) { @@ -73,8 +70,4 @@ public class GetFromVcsAction{ } }; } - - protected boolean isEnabled() { - return true; //To change body of implemented methods use File | Settings | File Templates. - } } diff --git a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java index a7bb024d72..33e594525d 100644 --- a/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java +++ b/ui/impl/com/intellij/openapi/wm/impl/welcomeScreen/WelcomeScreen.java @@ -77,6 +77,7 @@ public class WelcomeScreen { private static final Icon OPEN_PROJECT_ICON = IconLoader.getIcon("/general/openProject.png"); private static final Icon REOPEN_RECENT_ICON = IconLoader.getIcon("/general/reopenRecentProject.png"); private static final Icon FROM_VCS_ICON = IconLoader.getIcon("/general/getProjectfromVCS.png"); + private static final Icon IMPORT_ICON = IconLoader.getIcon("/general/getProjectfromVCS.png"); private static final Icon READ_HELP_ICON = IconLoader.getIcon("/general/readHelp.png"); private static final Icon PLUGIN_ICON = IconLoader.getIcon("/general/pluginManager.png"); private static final Icon DEFAULT_ICON = IconLoader.getIcon("/general/configurableDefault.png"); @@ -382,15 +383,7 @@ public class WelcomeScreen { MyActionButton openRecentProject = new ButtonWithExtension(REOPEN_RECENT_ICON, null) { protected void onPress(InputEvent e, final MyActionButton button) { - final AnAction action = new RecentProjectsAction(); - action.actionPerformed(new AnActionEvent(e, new DataContext() { - public Object getData(String dataId) { - if (DataConstants.PROJECT.equals(dataId)) { - return null; - } - return button; - } - }, ActionPlaces.UNKNOWN, new PresentationFactory().getPresentation(action), actionManager, 0)); + new RecentProjectsAction().showPopup(button, e); } }; quickStarts.addButton(openRecentProject, UIBundle.message("welcome.screen.reopen.recent.project.action.name"), @@ -398,14 +391,23 @@ public class WelcomeScreen { MyActionButton getFromVCS = new ButtonWithExtension(FROM_VCS_ICON, null) { protected void onPress(InputEvent e, final MyActionButton button) { - final GetFromVcsAction action = new GetFromVcsAction(); - action.actionPerformed(button, e); + new GetFromVcsAction().showPopup(button, e); } }; quickStarts.addButton(getFromVCS, UIBundle.message("welcome.screen.check.out.from.version.control.action.name"), UIBundle.message("welcome.screen.check.out.from.version.control.action.description")); + MyActionButton importProjects = new ButtonWithExtension(IMPORT_ICON, null) { + protected void onPress(InputEvent e, final MyActionButton button) { + new ProjectImportPopupAction().showPopup(button, e); + } + }; + + quickStarts.addButton(importProjects, + UIBundle.message("welcome.screen.import.projects.action.name"), + UIBundle.message("welcome.screen.import.projects.action.description")); + /* MyActionButton checkForUpdate = new MyActionButton (CHECK_FOR_UPDATE_ICON, null) { protected void onPress(InputEvent e) { -- 2.11.4.GIT