mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
added option to ignore invalid facet
This commit is contained in:
@@ -1,213 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 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.facet.impl.ui;
|
||||
|
||||
import com.intellij.facet.ui.FacetEditor;
|
||||
import com.intellij.facet.ui.MultipleFacetEditorHelper;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.ui.ThreeStateCheckBox;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class MultipleFacetEditorHelperImpl implements MultipleFacetEditorHelper {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.facet.ui.MultipleFacetSettingsEditor");
|
||||
private final List<AbstactBinding> myBindings = new ArrayList<AbstactBinding>();
|
||||
|
||||
public void bind(@NotNull ThreeStateCheckBox common, @NotNull FacetEditor[] editors, @NotNull NotNullFunction<FacetEditor, JCheckBox> fun) {
|
||||
List<JCheckBox> checkBoxesList = new ArrayList<JCheckBox>();
|
||||
for (FacetEditor editor : editors) {
|
||||
checkBoxesList.add(fun.fun(editor));
|
||||
}
|
||||
|
||||
CheckBoxBinding checkBoxBinding = new CheckBoxBinding(common, checkBoxesList);
|
||||
myBindings.add(checkBoxBinding);
|
||||
}
|
||||
|
||||
public void bind(@NotNull JTextField common, @NotNull FacetEditor[] editors, @NotNull NotNullFunction<FacetEditor, JTextField> fun) {
|
||||
List<JTextField> componentsList = new ArrayList<JTextField>();
|
||||
for (FacetEditor editor : editors) {
|
||||
componentsList.add(fun.fun(editor));
|
||||
}
|
||||
|
||||
TextFieldBinding binding = new TextFieldBinding(common, componentsList);
|
||||
myBindings.add(binding);
|
||||
}
|
||||
|
||||
public void bind(@NotNull JComboBox common, @NotNull FacetEditor[] editors, @NotNull NotNullFunction<FacetEditor, JComboBox> fun) {
|
||||
List<JComboBox> componentsList = new ArrayList<JComboBox>();
|
||||
for (FacetEditor editor : editors) {
|
||||
componentsList.add(fun.fun(editor));
|
||||
}
|
||||
|
||||
CombobBoxBinding binding = new CombobBoxBinding(common, componentsList);
|
||||
myBindings.add(binding);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
for (AbstactBinding binding : myBindings) {
|
||||
binding.unbind();
|
||||
}
|
||||
myBindings.clear();
|
||||
}
|
||||
|
||||
private static abstract class AbstactBinding {
|
||||
public abstract void unbind();
|
||||
}
|
||||
|
||||
private static class CheckBoxBinding extends AbstactBinding implements ActionListener {
|
||||
private final ThreeStateCheckBox myCommon;
|
||||
private final List<JCheckBox> myCheckBoxesList;
|
||||
private final List<Boolean> myInitialValues;
|
||||
|
||||
public CheckBoxBinding(final ThreeStateCheckBox common, final List<JCheckBox> checkBoxesList) {
|
||||
LOG.assertTrue(!checkBoxesList.isEmpty());
|
||||
myCommon = common;
|
||||
myCheckBoxesList = checkBoxesList;
|
||||
|
||||
Boolean initialValue = checkBoxesList.get(0).isSelected();
|
||||
myInitialValues = new ArrayList<Boolean>();
|
||||
for (JCheckBox checkBox : checkBoxesList) {
|
||||
boolean value = checkBox.isSelected();
|
||||
myInitialValues.add(value);
|
||||
if (initialValue != null && value != initialValue) {
|
||||
initialValue = null;
|
||||
}
|
||||
}
|
||||
if (initialValue != null) {
|
||||
common.setThirdStateEnabled(false);
|
||||
common.setSelected(initialValue);
|
||||
}
|
||||
else {
|
||||
common.setThirdStateEnabled(true);
|
||||
common.setState(ThreeStateCheckBox.State.DONT_CARE);
|
||||
}
|
||||
|
||||
myCommon.addActionListener(this);
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
ThreeStateCheckBox.State state = myCommon.getState();
|
||||
for (int i = 0; i < myCheckBoxesList.size(); i++) {
|
||||
boolean value = state == ThreeStateCheckBox.State.SELECTED ? true : state == ThreeStateCheckBox.State.NOT_SELECTED ? false : myInitialValues.get(i);
|
||||
JCheckBox checkBox = myCheckBoxesList.get(i);
|
||||
|
||||
if (value != checkBox.isSelected()) {
|
||||
ButtonModel model = checkBox.getModel();
|
||||
model.setArmed(true);
|
||||
model.setPressed(true);
|
||||
model.setPressed(false);
|
||||
model.setArmed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
myCommon.removeActionListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TextFieldBinding extends AbstactBinding {
|
||||
private final JTextField myCommon;
|
||||
private final List<JTextField> myTextFields;
|
||||
private final List<String> myInitialValues;
|
||||
private final DocumentAdapter myListener;
|
||||
|
||||
private TextFieldBinding(final JTextField common, final List<JTextField> textFields) {
|
||||
LOG.assertTrue(!textFields.isEmpty());
|
||||
myCommon = common;
|
||||
myTextFields = textFields;
|
||||
String initialValue = myTextFields.get(0).getText();
|
||||
myInitialValues = new ArrayList<String>();
|
||||
for (JTextField field : myTextFields) {
|
||||
String value = field.getText();
|
||||
myInitialValues.add(value);
|
||||
if (initialValue != null && !initialValue.equals(value)) {
|
||||
initialValue = null;
|
||||
}
|
||||
}
|
||||
common.setText(initialValue != null ? initialValue : "");
|
||||
|
||||
myListener = new DocumentAdapter() {
|
||||
protected void textChanged(final DocumentEvent e) {
|
||||
TextFieldBinding.this.textChanged();
|
||||
}
|
||||
};
|
||||
myCommon.getDocument().addDocumentListener(myListener);
|
||||
}
|
||||
|
||||
protected void textChanged() {
|
||||
String value = myCommon.getText();
|
||||
for (int i = 0; i < myTextFields.size(); i++) {
|
||||
myTextFields.get(i).setText(value.length() == 0 ? myInitialValues.get(i) : value);
|
||||
}
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
myCommon.getDocument().removeDocumentListener(myListener);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CombobBoxBinding extends AbstactBinding implements ItemListener {
|
||||
private final JComboBox myCommon;
|
||||
private final List<JComboBox> myComponentsList;
|
||||
private final List<Object> myInitialValues;
|
||||
|
||||
public CombobBoxBinding(final JComboBox common, final List<JComboBox> componentsList) {
|
||||
LOG.assertTrue(!componentsList.isEmpty());
|
||||
myCommon = common;
|
||||
myComponentsList = componentsList;
|
||||
|
||||
JComboBox first = componentsList.get(0);
|
||||
Object initialValue = first.getSelectedItem();
|
||||
|
||||
myInitialValues = new ArrayList<Object>();
|
||||
for (JComboBox component : componentsList) {
|
||||
Object item = component.getSelectedItem();
|
||||
myInitialValues.add(item);
|
||||
if (initialValue != null && !initialValue.equals(item)) {
|
||||
initialValue = null;
|
||||
}
|
||||
}
|
||||
common.setSelectedItem(initialValue);
|
||||
|
||||
common.addItemListener(this);
|
||||
}
|
||||
|
||||
public void unbind() {
|
||||
myCommon.removeItemListener(this);
|
||||
}
|
||||
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
Object item = myCommon.getSelectedItem();
|
||||
for (int i = 0; i < myComponentsList.size(); i++) {
|
||||
myComponentsList.get(i).setSelectedItem(item != null ? item : myInitialValues.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.ProjectFacetManager;
|
||||
import com.intellij.facet.impl.ProjectFacetsConfigurator;
|
||||
import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager;
|
||||
import com.intellij.facet.impl.invalid.InvalidFacetType;
|
||||
import com.intellij.facet.ui.DefaultFacetSettingsEditor;
|
||||
import com.intellij.facet.ui.FacetEditor;
|
||||
import com.intellij.facet.ui.MultipleFacetSettingsEditor;
|
||||
@@ -62,10 +63,12 @@ public class FacetTypeEditor extends UnnamedConfigurableGroup {
|
||||
myInitialConfigurables.add(new FacetAutodetectionConfigurable(project, context, facetType));
|
||||
}
|
||||
|
||||
C configuration = ProjectFacetManager.getInstance(project).createDefaultConfiguration(facetType);
|
||||
DefaultFacetSettingsEditor defaultSettingsEditor = facetType.createDefaultConfigurationEditor(project, configuration);
|
||||
if (defaultSettingsEditor != null) {
|
||||
myInitialConfigurables.add(new DefaultFacetSettingsConfigurable<C>(facetType, project, defaultSettingsEditor, configuration));
|
||||
if (!(facetType instanceof InvalidFacetType)) {
|
||||
C configuration = ProjectFacetManager.getInstance(project).createDefaultConfiguration(facetType);
|
||||
DefaultFacetSettingsEditor defaultSettingsEditor = facetType.createDefaultConfigurationEditor(project, configuration);
|
||||
if (defaultSettingsEditor != null) {
|
||||
myInitialConfigurables.add(new DefaultFacetSettingsConfigurable<C>(facetType, project, defaultSettingsEditor, configuration));
|
||||
}
|
||||
}
|
||||
|
||||
for (Configurable configurable : myInitialConfigurables) {
|
||||
|
||||
+1
-1
@@ -229,7 +229,7 @@ public class ProjectStructureConfigurable extends BaseConfigurable implements Se
|
||||
}
|
||||
|
||||
private void addFacetsConfig() {
|
||||
if (FacetStructureConfigurable.isEnabled()) {
|
||||
if (myFacetStructureConfigurable.isVisible()) {
|
||||
addConfigurable(myFacetStructureConfigurable);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-11
@@ -21,6 +21,8 @@ import com.intellij.facet.FacetType;
|
||||
import com.intellij.facet.FacetTypeRegistry;
|
||||
import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager;
|
||||
import com.intellij.facet.impl.autodetecting.FacetAutodetectingManagerImpl;
|
||||
import com.intellij.facet.impl.invalid.InvalidFacetManager;
|
||||
import com.intellij.facet.impl.invalid.InvalidFacetType;
|
||||
import com.intellij.facet.impl.ui.facetType.FacetTypeEditor;
|
||||
import com.intellij.facet.ui.FacetEditor;
|
||||
import com.intellij.facet.ui.MultipleFacetSettingsEditor;
|
||||
@@ -65,24 +67,31 @@ public class FacetStructureConfigurable extends BaseStructureConfigurable {
|
||||
return ServiceManager.getService(project, FacetStructureConfigurable.class);
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return FacetTypeRegistry.getInstance().getFacetTypes().length > 0;
|
||||
public boolean isVisible() {
|
||||
return FacetTypeRegistry.getInstance().getFacetTypes().length > 0 || !InvalidFacetManager.getInstance(myProject).getInvalidFacets().isEmpty();
|
||||
}
|
||||
|
||||
protected void loadTree() {
|
||||
myTree.setRootVisible(false);
|
||||
myTree.setShowsRootHandles(true);
|
||||
for (FacetType<?,?> facetType : FacetTypeRegistry.getInstance().getFacetTypes()) {
|
||||
FacetTypeConfigurable facetTypeConfigurable = new FacetTypeConfigurable(this, facetType);
|
||||
MyNode facetTypeNode = new MyNode(facetTypeConfigurable);
|
||||
addNode(facetTypeNode, myRoot);
|
||||
addFacetTypeNode(facetType);
|
||||
}
|
||||
if (!InvalidFacetManager.getInstance(myProject).getInvalidFacets().isEmpty()) {
|
||||
addFacetTypeNode(InvalidFacetType.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
for (Module module : myModuleManager.getModules()) {
|
||||
Collection<? extends Facet> facets = FacetManager.getInstance(module).getFacetsByType(facetType.getId());
|
||||
for (Facet facet : facets) {
|
||||
FacetEditorFacadeImpl editorFacade = ModuleStructureConfigurable.getInstance(myProject).getFacetEditorFacade();
|
||||
addFacetNode(facetTypeNode, facet, editorFacade);
|
||||
}
|
||||
private void addFacetTypeNode(FacetType<?, ?> facetType) {
|
||||
FacetTypeConfigurable facetTypeConfigurable = new FacetTypeConfigurable(this, facetType);
|
||||
MyNode facetTypeNode = new MyNode(facetTypeConfigurable);
|
||||
addNode(facetTypeNode, myRoot);
|
||||
|
||||
for (Module module : myModuleManager.getModules()) {
|
||||
Collection<? extends Facet> facets = FacetManager.getInstance(module).getFacetsByType(facetType.getId());
|
||||
FacetEditorFacadeImpl editorFacade = ModuleStructureConfigurable.getInstance(myProject).getFacetEditorFacade();
|
||||
for (Facet facet : facets) {
|
||||
addFacetNode(facetTypeNode, facet, editorFacade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user