mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
classpath panel refactored
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.openapi.roots.ModuleRootListener;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.impl.storage.ClasspathStorage;
|
||||
import com.intellij.openapi.roots.impl.storage.ClasspathStorageProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.classpath.ClasspathPanelImpl;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.ui.OrderPanelListener;
|
||||
@@ -46,7 +47,7 @@ public class ClasspathEditor extends ModuleElementsEditor implements ModuleRootL
|
||||
public static final String NAME = ProjectBundle.message("modules.classpath.title");
|
||||
public static final Icon ICON = IconLoader.getIcon("/modules/classpath.png");
|
||||
|
||||
private ClasspathPanel myPanel;
|
||||
private ClasspathPanelImpl myPanel;
|
||||
|
||||
private ClasspathFormatPanel myClasspathFormatPanel;
|
||||
|
||||
@@ -60,7 +61,7 @@ public class ClasspathEditor extends ModuleElementsEditor implements ModuleRootL
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return super.isModified() || ( myClasspathFormatPanel != null && myClasspathFormatPanel.isModified());
|
||||
return super.isModified() || (myClasspathFormatPanel != null && myClasspathFormatPanel.isModified());
|
||||
}
|
||||
|
||||
public String getHelpTopic() {
|
||||
@@ -96,7 +97,7 @@ public class ClasspathEditor extends ModuleElementsEditor implements ModuleRootL
|
||||
}
|
||||
|
||||
public JComponent createComponentImpl() {
|
||||
myPanel = new ClasspathPanel(getState());
|
||||
myPanel = new ClasspathPanelImpl(getState());
|
||||
|
||||
myPanel.addListener(new OrderPanelListener() {
|
||||
public void entryMoved() {
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.util.Disposer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
abstract class AddItemPopupAction<ItemType> extends ClasspathPanelAction {
|
||||
private final String myTitle;
|
||||
private final Icon myIcon;
|
||||
private final int myIndex;
|
||||
|
||||
public AddItemPopupAction(ClasspathPanel classpathPanel, int index, String title, Icon icon) {
|
||||
super(classpathPanel);
|
||||
myTitle = title;
|
||||
myIcon = icon;
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
final ClasspathElementChooserDialog<ItemType> dialog = createChooserDialog();
|
||||
if (dialog == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
dialog.doChoose();
|
||||
if (!dialog.isOK()) {
|
||||
return;
|
||||
}
|
||||
final List<ItemType> chosen = dialog.getChosenElements();
|
||||
if (chosen.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<ClasspathTableItem> toAdd = new ArrayList<ClasspathTableItem>();
|
||||
for (ItemType item : chosen) {
|
||||
final ClasspathTableItem tableItem = createTableItem(item);
|
||||
if (tableItem != null) {
|
||||
toAdd.add(tableItem);
|
||||
}
|
||||
}
|
||||
myClasspathPanel.addItems(toAdd);
|
||||
}
|
||||
finally {
|
||||
if (dialog instanceof ChooseNamedLibraryAction.MyChooserDialog) {
|
||||
Disposer.dispose(dialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract ClasspathTableItem createTableItem(final ItemType item);
|
||||
|
||||
@Nullable
|
||||
protected abstract ClasspathElementChooserDialog<ItemType> createChooserDialog();
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryFileChooser;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ChooseModuleLibrariesDialog extends LibraryFileChooser implements ClasspathElementChooserDialog<Library> {
|
||||
private Pair<String, VirtualFile[]> myLastChosen;
|
||||
private final LibraryTable myLibraryTable;
|
||||
@Nullable private final VirtualFile myFileToSelect;
|
||||
|
||||
public ChooseModuleLibrariesDialog(Component parent, final LibraryTable libraryTable, final VirtualFile fileToSelect) {
|
||||
super(createFileChooserDescriptor(parent), parent, false, null);
|
||||
myLibraryTable = libraryTable;
|
||||
myFileToSelect = fileToSelect;
|
||||
}
|
||||
|
||||
private static FileChooserDescriptor createFileChooserDescriptor(Component parent) {
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(false, true, true, false, false, true);
|
||||
final Module contextModule = LangDataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(parent));
|
||||
descriptor.putUserData(LangDataKeys.MODULE_CONTEXT, contextModule);
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
public java.util.List<Library> getChosenElements() {
|
||||
if (myLastChosen == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final VirtualFile[] files = filterAlreadyAdded(myLastChosen.getSecond());
|
||||
if (files.length == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final LibraryTable.ModifiableModel modifiableModel = myLibraryTable.getModifiableModel();
|
||||
final java.util.List<Library> addedLibraries = new ArrayList<Library>(files.length);
|
||||
for (VirtualFile file : files) {
|
||||
final Library library = modifiableModel.createLibrary(null);
|
||||
final Library.ModifiableModel libModel = library.getModifiableModel();
|
||||
libModel.addRoot(file, OrderRootType.CLASSES);
|
||||
libModel.commit();
|
||||
addedLibraries.add(library);
|
||||
}
|
||||
return addedLibraries;
|
||||
}
|
||||
|
||||
private VirtualFile[] filterAlreadyAdded(final VirtualFile[] files) {
|
||||
if (files == null || files.length == 0) {
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
final Set<VirtualFile> chosenFilesSet = new HashSet<VirtualFile>(Arrays.asList(files));
|
||||
final Set<VirtualFile> alreadyAdded = new HashSet<VirtualFile>();
|
||||
final Library[] libraries = myLibraryTable.getLibraries();
|
||||
for (Library library : libraries) {
|
||||
ContainerUtil.addAll(alreadyAdded, library.getFiles(OrderRootType.CLASSES));
|
||||
}
|
||||
chosenFilesSet.removeAll(alreadyAdded);
|
||||
return VfsUtil.toVirtualFileArray(chosenFilesSet);
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
myLastChosen = chooseNameAndFiles(myFileToSelect);
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.util.Icons;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ChooseNamedLibraryAction extends AddItemPopupAction<Library> {
|
||||
private final LibraryTableModifiableModelProvider myLibraryTableModelProvider;
|
||||
|
||||
public ChooseNamedLibraryAction(ClasspathPanel classpathPanel,
|
||||
final int index,
|
||||
final String title,
|
||||
final LibraryTableModifiableModelProvider libraryTable) {
|
||||
super(classpathPanel, index, title, Icons.LIBRARY_ICON);
|
||||
myLibraryTableModelProvider = libraryTable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected ClasspathTableItem createTableItem(final Library item) {
|
||||
// clear invalid order entry corresponding to added library if any
|
||||
final ModifiableRootModel rootModel = myClasspathPanel.getRootModel();
|
||||
final OrderEntry[] orderEntries = rootModel.getOrderEntries();
|
||||
for (OrderEntry orderEntry : orderEntries) {
|
||||
if (orderEntry instanceof LibraryOrderEntry) {
|
||||
if (item.getName().equals(((LibraryOrderEntry)orderEntry).getLibraryName())) {
|
||||
if (orderEntry.isValid()) {
|
||||
Messages.showErrorDialog(ProjectBundle.message("classpath.message.library.already.added",item.getName()),
|
||||
ProjectBundle.message("classpath.title.adding.dependency"));
|
||||
return null;
|
||||
} else {
|
||||
rootModel.removeOrderEntry(orderEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ClasspathTableItem.createLibItem(rootModel.addLibraryEntry(item));
|
||||
}
|
||||
|
||||
protected ClasspathElementChooserDialog<Library> createChooserDialog() {
|
||||
return new MyChooserDialog();
|
||||
}
|
||||
|
||||
private Collection<Library> getAlreadyAddedLibraries() {
|
||||
final OrderEntry[] orderEntries = myClasspathPanel.getRootModel().getOrderEntries();
|
||||
final Set<Library> result = new HashSet<Library>(orderEntries.length);
|
||||
for (OrderEntry orderEntry : orderEntries) {
|
||||
if (orderEntry instanceof LibraryOrderEntry && orderEntry.isValid()) {
|
||||
final LibraryImpl library = (LibraryImpl)((LibraryOrderEntry)orderEntry).getLibrary();
|
||||
if (library != null) {
|
||||
result.add(library.getSource());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
class MyChooserDialog implements ClasspathElementChooserDialog<Library> {
|
||||
private final LibraryTableEditor myEditor;
|
||||
private Library[] myLibraries;
|
||||
|
||||
MyChooserDialog(){
|
||||
myEditor = LibraryTableEditor.editLibraryTable(myLibraryTableModelProvider, myClasspathPanel.getProject());
|
||||
Disposer.register(this, myEditor);
|
||||
}
|
||||
|
||||
public List<Library> getChosenElements() {
|
||||
final List<Library> chosen = new ArrayList<Library>(Arrays.asList(myLibraries));
|
||||
chosen.removeAll(getAlreadyAddedLibraries());
|
||||
return chosen;
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
final Iterator iter = myLibraryTableModelProvider.getModifiableModel().getLibraryIterator();
|
||||
myLibraries = myEditor.openDialog(myClasspathPanel.getComponent(), iter.hasNext()? Collections.singleton((Library)iter.next()) : Collections.<Library>emptyList(), false);
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return myLibraries != null;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.Disposable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
interface ClasspathElementChooserDialog<T> extends Disposable {
|
||||
List<T> getChosenElements();
|
||||
void doChoose();
|
||||
boolean isOK();
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.project.Project;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public interface ClasspathPanel {
|
||||
void runClasspathPanelAction(Runnable action);
|
||||
|
||||
void addItems(List<ClasspathTableItem> toAdd);
|
||||
|
||||
ModifiableRootModel getRootModel();
|
||||
|
||||
Project getProject();
|
||||
|
||||
JComponent getComponent();
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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 java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
abstract class ClasspathPanelAction implements ActionListener, Runnable {
|
||||
protected final ClasspathPanel myClasspathPanel;
|
||||
|
||||
protected ClasspathPanelAction(ClasspathPanel classpathPanel) {
|
||||
myClasspathPanel = classpathPanel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
execute();
|
||||
}
|
||||
|
||||
public final void execute() {
|
||||
myClasspathPanel.runClasspathPanelAction(this);
|
||||
}
|
||||
}
|
||||
+138
-643
File diff suppressed because it is too large
Load Diff
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.roots.*;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ClasspathTableItem {
|
||||
@Nullable protected final OrderEntry myEntry;
|
||||
private final boolean myRemovable;
|
||||
|
||||
@Nullable
|
||||
public static ClasspathTableItem createItem(OrderEntry orderEntry) {
|
||||
if (orderEntry instanceof JdkOrderEntry) {
|
||||
return new ClasspathTableItem(orderEntry, false);
|
||||
}
|
||||
else if (orderEntry instanceof LibraryOrderEntry) {
|
||||
return createLibItem((LibraryOrderEntry)orderEntry);
|
||||
}
|
||||
else if (orderEntry instanceof ModuleOrderEntry) {
|
||||
return new ClasspathTableItem(orderEntry, true);
|
||||
}
|
||||
else if (orderEntry instanceof ModuleSourceOrderEntry) {
|
||||
return new ClasspathTableItem(orderEntry, false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ClasspathTableItem createLibItem(LibraryOrderEntry orderEntry) {
|
||||
return new ClasspathTableItem(orderEntry, true) {
|
||||
public boolean isEditable() {
|
||||
return myEntry != null && myEntry.isValid();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected ClasspathTableItem(@Nullable OrderEntry entry, boolean removable) {
|
||||
myEntry = entry;
|
||||
myRemovable = removable;
|
||||
}
|
||||
|
||||
public final boolean isExportable() {
|
||||
return myEntry instanceof ExportableOrderEntry;
|
||||
}
|
||||
|
||||
public final boolean isExported() {
|
||||
return myEntry instanceof ExportableOrderEntry && ((ExportableOrderEntry)myEntry).isExported();
|
||||
}
|
||||
|
||||
public final void setExported(boolean isExported) {
|
||||
if (myEntry instanceof ExportableOrderEntry) {
|
||||
((ExportableOrderEntry)myEntry).setExported(isExported);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final DependencyScope getScope() {
|
||||
return myEntry instanceof ExportableOrderEntry ? ((ExportableOrderEntry) myEntry).getScope() : null;
|
||||
}
|
||||
|
||||
public final void setScope(DependencyScope scope) {
|
||||
if (myEntry instanceof ExportableOrderEntry) {
|
||||
((ExportableOrderEntry) myEntry).setScope(scope);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final OrderEntry getEntry() {
|
||||
return myEntry;
|
||||
}
|
||||
|
||||
public boolean isRemovable() {
|
||||
return myRemovable;
|
||||
}
|
||||
|
||||
public boolean isEditable() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.roots.ui.configuration.ModuleConfigurationState;
|
||||
import com.intellij.util.ui.ItemRemovable;
|
||||
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class ClasspathTableModel extends AbstractTableModel implements ItemRemovable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.classpath.ClasspathTableModel");
|
||||
public static final String EXPORT_COLUMN_NAME = ProjectBundle.message("modules.order.export.export.column");
|
||||
private static final String SCOPE_COLUMN_NAME = ProjectBundle.message("modules.order.export.scope.column");
|
||||
public static final int EXPORT_COLUMN = 0;
|
||||
public static final int ITEM_COLUMN = 1;
|
||||
public static final int SCOPE_COLUMN = 2;
|
||||
private final List<ClasspathTableItem> myItems = new ArrayList<ClasspathTableItem>();
|
||||
private final ModuleConfigurationState myState;
|
||||
|
||||
public ClasspathTableModel(final ModuleConfigurationState state) {
|
||||
myState = state;
|
||||
init();
|
||||
}
|
||||
|
||||
private ModifiableRootModel getModel() {
|
||||
return myState.getRootModel();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
final OrderEntry[] orderEntries = getModel().getOrderEntries();
|
||||
boolean hasJdkOrderEntry = false;
|
||||
for (final OrderEntry orderEntry : orderEntries) {
|
||||
if (orderEntry instanceof JdkOrderEntry) {
|
||||
hasJdkOrderEntry = true;
|
||||
}
|
||||
addItem(ClasspathTableItem.createItem(orderEntry));
|
||||
}
|
||||
if (!hasJdkOrderEntry) {
|
||||
addItemAt(new InvalidJdkItem(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public ClasspathTableItem getItemAt(int row) {
|
||||
return myItems.get(row);
|
||||
}
|
||||
|
||||
public void addItem(ClasspathTableItem item) {
|
||||
myItems.add(item);
|
||||
}
|
||||
|
||||
public void addItemAt(ClasspathTableItem item, int row) {
|
||||
myItems.add(row, item);
|
||||
}
|
||||
|
||||
public ClasspathTableItem removeDataRow(int row) {
|
||||
return myItems.remove(row);
|
||||
}
|
||||
|
||||
public void removeRow(int row) {
|
||||
removeDataRow(row);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
myItems.clear();
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return myItems.size();
|
||||
}
|
||||
|
||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||
final ClasspathTableItem item = myItems.get(rowIndex);
|
||||
if (columnIndex == EXPORT_COLUMN) {
|
||||
return item.isExported();
|
||||
}
|
||||
if (columnIndex == SCOPE_COLUMN) {
|
||||
return item.getScope();
|
||||
}
|
||||
if (columnIndex == ITEM_COLUMN) {
|
||||
return item;
|
||||
}
|
||||
LOG.error("Incorrect column index: " + columnIndex);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
|
||||
final ClasspathTableItem item = myItems.get(rowIndex);
|
||||
if (columnIndex == EXPORT_COLUMN) {
|
||||
item.setExported(((Boolean)aValue).booleanValue());
|
||||
}
|
||||
else if (columnIndex == SCOPE_COLUMN && aValue instanceof DependencyScope) {
|
||||
item.setScope((DependencyScope) aValue);
|
||||
}
|
||||
}
|
||||
|
||||
public String getColumnName(int column) {
|
||||
if (column == EXPORT_COLUMN) {
|
||||
return EXPORT_COLUMN_NAME;
|
||||
}
|
||||
if (column == SCOPE_COLUMN) {
|
||||
return SCOPE_COLUMN_NAME;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public Class getColumnClass(int column) {
|
||||
if (column == EXPORT_COLUMN) {
|
||||
return Boolean.class;
|
||||
}
|
||||
if (column == SCOPE_COLUMN) {
|
||||
return DependencyScope.class;
|
||||
}
|
||||
if (column == ITEM_COLUMN) {
|
||||
return ClasspathTableItem.class;
|
||||
}
|
||||
return super.getColumnClass(column);
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
if (column == EXPORT_COLUMN || column == SCOPE_COLUMN) {
|
||||
final ClasspathTableItem item = myItems.get(row);
|
||||
return item != null && item.isExportable();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.DataKeys;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTablePresentation;
|
||||
import com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider;
|
||||
import com.intellij.openapi.roots.ui.configuration.libraryEditor.LibraryTableEditor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
class CreateModuleLibraryDialog implements ClasspathElementChooserDialog<Library> {
|
||||
private boolean myIsOk;
|
||||
private final ClasspathPanel myClasspathPanel;
|
||||
private final LibraryTable myLibraryTable;
|
||||
private Library myChosenLibrary;
|
||||
|
||||
public CreateModuleLibraryDialog(ClasspathPanel classpathPanel, final LibraryTable libraryTable) {
|
||||
myClasspathPanel = classpathPanel;
|
||||
myLibraryTable = libraryTable;
|
||||
}
|
||||
|
||||
public List<Library> getChosenElements() {
|
||||
return myChosenLibrary == null? Collections.<Library>emptyList() : Collections.singletonList(myChosenLibrary);
|
||||
}
|
||||
|
||||
public void doChoose() {
|
||||
final LibraryTable.ModifiableModel libraryModifiableModel = myLibraryTable.getModifiableModel();
|
||||
final LibraryTableModifiableModelProvider provider = new LibraryTableModifiableModelProvider() {
|
||||
public LibraryTable.ModifiableModel getModifiableModel() {
|
||||
return libraryModifiableModel;
|
||||
}
|
||||
|
||||
public String getTableLevel() {
|
||||
return myLibraryTable.getTableLevel();
|
||||
}
|
||||
|
||||
public LibraryTablePresentation getLibraryTablePresentation() {
|
||||
return myLibraryTable.getPresentation();
|
||||
}
|
||||
|
||||
public boolean isLibraryTableEditable() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
final Library library = myLibraryTable.createLibrary();
|
||||
final LibraryTableEditor editor = LibraryTableEditor.editLibrary(provider, library, myClasspathPanel.getProject());
|
||||
final Module contextModule = DataKeys.MODULE_CONTEXT.getData(DataManager.getInstance().getDataContext(myClasspathPanel.getComponent()));
|
||||
editor.addFileChooserContext(LangDataKeys.MODULE_CONTEXT, contextModule);
|
||||
myIsOk = editor.openDialog(myClasspathPanel.getComponent(), Collections.singletonList(library), true) != null;
|
||||
if (myIsOk) {
|
||||
myChosenLibrary = library;
|
||||
}
|
||||
else {
|
||||
myChosenLibrary = null;
|
||||
libraryModifiableModel.removeLibrary(library);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOK() {
|
||||
return myIsOk;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class InvalidJdkItem extends ClasspathTableItem {
|
||||
public InvalidJdkItem() {
|
||||
super(null, false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user