mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactored
This commit is contained in:
+5
-5
@@ -40,11 +40,11 @@ import java.util.List;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class AddLibraryAction extends AddItemPopupAction<Library> {
|
||||
class AddLibraryDependencyAction extends AddItemPopupAction<Library> {
|
||||
private final StructureConfigurableContext myContext;
|
||||
|
||||
public AddLibraryAction(ClasspathPanel classpathPanel, final int index, final String title,
|
||||
final StructureConfigurableContext context) {
|
||||
public AddLibraryDependencyAction(ClasspathPanel classpathPanel, final int index, final String title,
|
||||
final StructureConfigurableContext context) {
|
||||
super(classpathPanel, index, title, PlatformIcons.LIBRARY_ICON);
|
||||
myContext = context;
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class AddLibraryAction extends AddItemPopupAction<Library> {
|
||||
return LibraryEditingUtil.createChooseTypeStep(myClasspathPanel, new ParameterizedRunnable<LibraryType>() {
|
||||
@Override
|
||||
public void run(LibraryType libraryType) {
|
||||
new AddNewLibraryItemAction(myClasspathPanel, myContext, libraryType).execute();
|
||||
new AddNewLibraryDependencyAction(myClasspathPanel, myContext, libraryType).execute();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class AddLibraryAction extends AddItemPopupAction<Library> {
|
||||
super.run();
|
||||
}
|
||||
else {
|
||||
new AddNewLibraryItemAction(myClasspathPanel, myContext, null).run();
|
||||
new AddNewLibraryDependencyAction(myClasspathPanel, myContext, null).run();
|
||||
}
|
||||
}
|
||||
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright 2000-2011 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ui.configuration.ChooseModulesDialog;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.StructureConfigurableContext;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class AddModuleDependencyAction extends AddItemPopupAction<Module> {
|
||||
private final StructureConfigurableContext myContext;
|
||||
private final ClasspathPanel myClasspathPanel;
|
||||
|
||||
public AddModuleDependencyAction(final ClasspathPanel classpathPanel,
|
||||
int actionIndex,
|
||||
StructureConfigurableContext context) {
|
||||
super(classpathPanel, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"),
|
||||
StdModuleTypes.JAVA.getNodeIcon(false));
|
||||
myContext = context;
|
||||
myClasspathPanel = classpathPanel;
|
||||
}
|
||||
|
||||
protected ClasspathTableItem<?> createTableItem(final Module item) {
|
||||
return ClasspathTableItem.createItem(myClasspathPanel.getRootModel().addModuleOrderEntry(item), myContext);
|
||||
}
|
||||
|
||||
private List<Module> getNotAddedModules() {
|
||||
final ModifiableRootModel rootModel = myClasspathPanel.getRootModel();
|
||||
Set<Module> addedModules = new HashSet<Module>(Arrays.asList(rootModel.getModuleDependencies(true)));
|
||||
addedModules.add(rootModel.getModule());
|
||||
|
||||
final Module[] modules = myClasspathPanel.getModuleConfigurationState().getModulesProvider().getModules();
|
||||
final List<Module> elements = new ArrayList<Module>();
|
||||
for (final Module module : modules) {
|
||||
if (!addedModules.contains(module)) {
|
||||
elements.add(module);
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
protected ClasspathElementChooser<Module> createChooser() {
|
||||
final List<Module> chooseItems = getNotAddedModules();
|
||||
if (chooseItems.isEmpty()) {
|
||||
Messages.showMessageDialog(myClasspathPanel.getComponent(), ProjectBundle.message("message.no.module.dependency.candidates"), getTitle(),
|
||||
Messages.getInformationIcon());
|
||||
return null;
|
||||
}
|
||||
return new ModuleChooser(myClasspathPanel, chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"),
|
||||
ProjectBundle.message("classpath.chooser.description.add.module.dependency"));
|
||||
}
|
||||
|
||||
private static class ModuleChooser implements ClasspathElementChooser<Module> {
|
||||
private final List<Module> myItems;
|
||||
private final String myTitle;
|
||||
private final String myDescription;
|
||||
private final ClasspathPanel myClasspathPanel;
|
||||
|
||||
public ModuleChooser(final ClasspathPanel classpathPanel,
|
||||
final List<Module> items,
|
||||
final String title,
|
||||
String description) {
|
||||
myItems = items;
|
||||
myTitle = title;
|
||||
myDescription = description;
|
||||
myClasspathPanel = classpathPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Module> chooseElements() {
|
||||
ChooseModulesDialog dialog = new ChooseModulesDialog(myClasspathPanel.getComponent(), myItems, myTitle, myDescription);
|
||||
dialog.show();
|
||||
return dialog.getChosenElements();
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -32,12 +32,12 @@ import javax.swing.*;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class AddNewLibraryItemAction extends ChooseAndAddAction<Library> {
|
||||
class AddNewLibraryDependencyAction extends ChooseAndAddAction<Library> {
|
||||
private final StructureConfigurableContext myContext;
|
||||
private final LibraryType myLibraryType;
|
||||
|
||||
public AddNewLibraryItemAction(final ClasspathPanel classpathPanel,
|
||||
StructureConfigurableContext context, LibraryType libraryType) {
|
||||
public AddNewLibraryDependencyAction(final ClasspathPanel classpathPanel,
|
||||
StructureConfigurableContext context, LibraryType libraryType) {
|
||||
super(classpathPanel);
|
||||
myContext = context;
|
||||
myLibraryType = libraryType;
|
||||
+5
-5
@@ -27,13 +27,13 @@ import com.intellij.util.PlatformIcons;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class AddModuleLibraryAction extends AddItemPopupAction<Library> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.AddModuleLibraryAction");
|
||||
class AddNewModuleLibraryAction extends AddItemPopupAction<Library> {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.AddNewModuleLibraryAction");
|
||||
private final StructureConfigurableContext myContext;
|
||||
|
||||
public AddModuleLibraryAction(final ClasspathPanel classpathPanel,
|
||||
int actionIndex,
|
||||
StructureConfigurableContext context) {
|
||||
public AddNewModuleLibraryAction(final ClasspathPanel classpathPanel,
|
||||
int actionIndex,
|
||||
StructureConfigurableContext context) {
|
||||
super(classpathPanel, actionIndex, ProjectBundle.message("classpath.add.simple.module.library.action"), PlatformIcons.JAR_ICON);
|
||||
myContext = context;
|
||||
}
|
||||
+4
-65
@@ -17,7 +17,6 @@ package com.intellij.openapi.roots.ui.configuration.classpath;
|
||||
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -41,7 +40,6 @@ import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ModuleProj
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.ProjectStructureElement;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.daemon.SdkProjectStructureElement;
|
||||
import com.intellij.openapi.ui.ComboBoxTableRenderer;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.ui.popup.PopupStep;
|
||||
@@ -67,10 +65,8 @@ import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
private final JBTable myEntryTable;
|
||||
@@ -484,23 +480,9 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
int actionIndex = 1;
|
||||
final List<AddItemPopupAction<?>> actions = new ArrayList<AddItemPopupAction<?>>();
|
||||
final StructureConfigurableContext context = getStructureConfigurableContext();
|
||||
actions.add(new AddModuleLibraryAction(this, actionIndex++, context));
|
||||
actions.add(new AddLibraryAction(this, actionIndex++, ProjectBundle.message("classpath.add.library.action"), context));
|
||||
actions.add(new AddItemPopupAction<Module>(this, actionIndex, ProjectBundle.message("classpath.add.module.dependency.action"),
|
||||
StdModuleTypes.JAVA.getNodeIcon(false)) {
|
||||
protected ClasspathTableItem<?> createTableItem(final Module item) {
|
||||
return ClasspathTableItem.createItem(getRootModel().addModuleOrderEntry(item), context);
|
||||
}
|
||||
protected ClasspathElementChooser<Module> createChooser() {
|
||||
final List<Module> chooseItems = getDependencyModules();
|
||||
if (chooseItems.isEmpty()) {
|
||||
Messages.showMessageDialog(ClasspathPanelImpl.this, ProjectBundle.message("message.no.module.dependency.candidates"), getTitle(), Messages.getInformationIcon());
|
||||
return null;
|
||||
}
|
||||
return new ModuleChooser(chooseItems, ProjectBundle.message("classpath.chooser.title.add.module.dependency"),
|
||||
ProjectBundle.message("classpath.chooser.description.add.module.dependency"));
|
||||
}
|
||||
}
|
||||
actions.add(new AddNewModuleLibraryAction(this, actionIndex++, context));
|
||||
actions.add(new AddLibraryDependencyAction(this, actionIndex++, ProjectBundle.message("classpath.add.library.action"), context));
|
||||
actions.add(new AddModuleDependencyAction(this, actionIndex, context)
|
||||
);
|
||||
|
||||
myPopupActions = actions;
|
||||
@@ -602,29 +584,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
TableUtil.selectRows(myEntryTable, selection);
|
||||
}
|
||||
|
||||
private List<Module> getDependencyModules() {
|
||||
final int rowCount = myModel.getRowCount();
|
||||
final Set<String> filtered = new HashSet<String>(rowCount);
|
||||
for (int row = 0; row < rowCount; row++) {
|
||||
final OrderEntry entry = myModel.getItemAt(row).getEntry();
|
||||
if (entry instanceof ModuleOrderEntry) {
|
||||
filtered.add(((ModuleOrderEntry)entry).getModuleName());
|
||||
}
|
||||
}
|
||||
final ModulesProvider modulesProvider = myState.getModulesProvider();
|
||||
final Module self = modulesProvider.getModule(getRootModel().getModule().getName());
|
||||
filtered.add(self.getName());
|
||||
|
||||
final Module[] modules = modulesProvider.getModules();
|
||||
final List<Module> elements = new ArrayList<Module>(modules.length);
|
||||
for (final Module module : modules) {
|
||||
if (!filtered.contains(module.getName())) {
|
||||
elements.add(module);
|
||||
}
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
private static CellAppearanceEx getCellAppearance(final ClasspathTableItem<?> item,
|
||||
final StructureConfigurableContext context,
|
||||
final boolean selected) {
|
||||
@@ -677,25 +636,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
}
|
||||
}
|
||||
|
||||
private class ModuleChooser implements ClasspathElementChooser<Module> {
|
||||
private final List<Module> myItems;
|
||||
private final String myTitle;
|
||||
private final String myDescription;
|
||||
|
||||
public ModuleChooser(final List<Module> items, final String title, String description) {
|
||||
myItems = items;
|
||||
myTitle = title;
|
||||
myDescription = description;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Module> chooseElements() {
|
||||
ChooseModulesDialog dialog = new ChooseModulesDialog(ClasspathPanelImpl.this, myItems, myTitle, myDescription);
|
||||
dialog.show();
|
||||
return dialog.getChosenElements();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyFindUsagesAction extends FindUsagesInProjectStructureActionBase {
|
||||
private MyFindUsagesAction() {
|
||||
super(myEntryTable, myState.getProject());
|
||||
@@ -735,5 +675,4 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel {
|
||||
return new RelativePoint(myEntryTable, location);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-10
@@ -169,16 +169,16 @@ public class ProjectStructureChooseLibrariesDialog extends ChooseLibrariesFromTa
|
||||
|
||||
@Override
|
||||
protected void doAction(ActionEvent e) {
|
||||
AddNewLibraryItemAction.chooseTypeAndCreate(myClasspathPanel, myContext, myCreateLibraryButton,
|
||||
new AddNewLibraryItemAction.LibraryCreatedCallback() {
|
||||
@Override
|
||||
public void libraryCreated(@NotNull Library library) {
|
||||
if (library.getTable() == null) {
|
||||
myCreatedModuleLibraries.add(library);
|
||||
}
|
||||
queueUpdateAndSelect(library);
|
||||
}
|
||||
});
|
||||
AddNewLibraryDependencyAction.chooseTypeAndCreate(myClasspathPanel, myContext, myCreateLibraryButton,
|
||||
new AddNewLibraryDependencyAction.LibraryCreatedCallback() {
|
||||
@Override
|
||||
public void libraryCreated(@NotNull Library library) {
|
||||
if (library.getTable() == null) {
|
||||
myCreatedModuleLibraries.add(library);
|
||||
}
|
||||
queueUpdateAndSelect(library);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user