mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
moving ValidationConfigurable to community so that validation configuration UI is available even if javaee plugins are disabled
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package com.intellij.compiler.options;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.compiler.options.ExcludeEntryDescription;
|
||||
import com.intellij.openapi.compiler.options.ExcludesConfiguration;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class ExcludeFromValidationAction extends AnAction {
|
||||
|
||||
public ExcludeFromValidationAction() {
|
||||
super(CompilerBundle.message("action.name.exclude.from.validation"));
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
final Pair<ExcludesConfiguration, VirtualFile> pair = getExcludedConfigurationAndFile(e, project);
|
||||
if (pair == null) return;
|
||||
final ExcludeEntryDescription description = new ExcludeEntryDescription(pair.getSecond(), false, true, project);
|
||||
pair.getFirst().addExcludeEntryDescription(description);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Pair<ExcludesConfiguration, VirtualFile> getExcludedConfigurationAndFile(final AnActionEvent event, Project project) {
|
||||
Navigatable navigatable = event.getData(CommonDataKeys.NAVIGATABLE);
|
||||
if (project != null && navigatable instanceof OpenFileDescriptor) {
|
||||
final VirtualFile file = ((OpenFileDescriptor)navigatable).getFile();
|
||||
final ExcludesConfiguration configuration = ValidationConfiguration.getExcludedEntriesConfiguration(project);
|
||||
return Pair.create(configuration, file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
final boolean applicable = getExcludedConfigurationAndFile(e, project) != null;
|
||||
e.getPresentation().setVisible(applicable);
|
||||
e.getPresentation().setEnabled(applicable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.compiler.options.ValidationConfigurable">
|
||||
<grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="244"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="a723a" class="javax.swing.JCheckBox" binding="myValidateBox">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="Validate on build"/>
|
||||
</properties>
|
||||
</component>
|
||||
<grid id="8effc" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="0">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="f7bde" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndentWithoutInsets"/>
|
||||
</clientProperties>
|
||||
<border type="etched" title="Validators"/>
|
||||
<children>
|
||||
<component id="3dfdb" class="com.intellij.ide.util.ElementsChooser" binding="myValidators" custom-create="true" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<colorUnmarkedElements value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="73218" binding="myExcludedEntriesPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndentWithoutInsets"/>
|
||||
</clientProperties>
|
||||
<border type="etched" title="Exclude From Validation"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<component id="33830" class="com.intellij.openapi.ui.Splitter">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<firstComponent value="f7bde"/>
|
||||
<orientation value="true"/>
|
||||
<secondComponent value="73218"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -0,0 +1,171 @@
|
||||
package com.intellij.compiler.options;
|
||||
|
||||
import com.intellij.ide.util.ElementsChooser;
|
||||
import com.intellij.openapi.compiler.Compiler;
|
||||
import com.intellij.openapi.compiler.CompilerBundle;
|
||||
import com.intellij.openapi.compiler.CompilerManager;
|
||||
import com.intellij.openapi.compiler.Validator;
|
||||
import com.intellij.openapi.compiler.generic.GenericCompiler;
|
||||
import com.intellij.openapi.compiler.options.ExcludedEntriesConfigurable;
|
||||
import com.intellij.openapi.compiler.options.ExcludesConfiguration;
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.uiDesigner.core.GridConstraints;
|
||||
import com.intellij.util.NullableFunction;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public class ValidationConfigurable implements SearchableConfigurable, Configurable.NoScroll {
|
||||
|
||||
private JPanel myPanel;
|
||||
private JCheckBox myValidateBox;
|
||||
private ElementsChooser<Compiler> myValidators;
|
||||
private JPanel myExcludedEntriesPanel;
|
||||
private final Project myProject;
|
||||
private final ValidationConfiguration myConfiguration;
|
||||
private final ExcludedEntriesConfigurable myExcludedConfigurable;
|
||||
|
||||
public ValidationConfigurable(final Project project) {
|
||||
myProject = project;
|
||||
myConfiguration = ValidationConfiguration.getInstance(myProject);
|
||||
myExcludedConfigurable = createExcludedConfigurable(project);
|
||||
|
||||
myValidators.getEmptyText().setText(CompilerBundle.message("no.validators"));
|
||||
}
|
||||
|
||||
private static ExcludedEntriesConfigurable createExcludedConfigurable(final Project project) {
|
||||
final ExcludesConfiguration configuration = ValidationConfiguration.getExcludedEntriesConfiguration(project);
|
||||
final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true) {
|
||||
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
|
||||
return super.isFileVisible(file, showHiddenFiles) && (project.isDefault() || !index.isExcluded(file));
|
||||
}
|
||||
};
|
||||
|
||||
List<VirtualFile> allContentRoots = new ArrayList<VirtualFile>();
|
||||
for (final Module module: ModuleManager.getInstance(project).getModules()) {
|
||||
final VirtualFile[] moduleContentRoots = ModuleRootManager.getInstance(module).getContentRoots();
|
||||
Collections.addAll(allContentRoots, moduleContentRoots);
|
||||
}
|
||||
descriptor.setRoots(allContentRoots);
|
||||
return new ExcludedEntriesConfigurable(project, descriptor, configuration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getId() {
|
||||
return "project.validation";
|
||||
}
|
||||
|
||||
public Runnable enableSearch(final String option) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return CompilerBundle.message("validation.display.name");
|
||||
}
|
||||
|
||||
public String getHelpTopic() {
|
||||
return "reference.projectsettings.compiler.validation";
|
||||
}
|
||||
|
||||
public JComponent createComponent() {
|
||||
final GridConstraints constraints = new GridConstraints();
|
||||
constraints.setFill(GridConstraints.FILL_BOTH);
|
||||
myExcludedEntriesPanel.add(myExcludedConfigurable.createComponent(), constraints);
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
List<Compiler> selectedElements = myValidators.getMarkedElements();
|
||||
List<Compiler> markedValidators = getMarkedValidators();
|
||||
if (markedValidators.size() != selectedElements.size()) {
|
||||
return true;
|
||||
}
|
||||
Set<Compiler> set = new THashSet<Compiler>(selectedElements, new TObjectHashingStrategy<Compiler>() {
|
||||
public int computeHashCode(Compiler object) {
|
||||
return object.getDescription().hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Compiler o1, Compiler o2) {
|
||||
return o1.getDescription().equals(o2.getDescription());
|
||||
}
|
||||
});
|
||||
return myConfiguration.VALIDATE_ON_BUILD != myValidateBox.isSelected() ||
|
||||
set.retainAll(markedValidators) ||
|
||||
myExcludedConfigurable.isModified();
|
||||
}
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
myConfiguration.VALIDATE_ON_BUILD = myValidateBox.isSelected();
|
||||
for (int i = 0; i < myValidators.getElementCount(); i++) {
|
||||
final Compiler validator = myValidators.getElementAt(i);
|
||||
myConfiguration.setSelected(validator, myValidators.isElementMarked(validator));
|
||||
}
|
||||
myExcludedConfigurable.apply();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
myValidateBox.setSelected(myConfiguration.VALIDATE_ON_BUILD);
|
||||
final List<Compiler> validators = getValidators();
|
||||
Collections.sort(validators, new Comparator<Compiler>() {
|
||||
public int compare(final Compiler o1, final Compiler o2) {
|
||||
return o1.getDescription().compareTo(o2.getDescription());
|
||||
}
|
||||
});
|
||||
myValidators.setElements(validators, false);
|
||||
myValidators.markElements(getMarkedValidators());
|
||||
myExcludedConfigurable.reset();
|
||||
}
|
||||
|
||||
private List<Compiler> getMarkedValidators() {
|
||||
final List<Compiler> validators = getValidators();
|
||||
return ContainerUtil.mapNotNull(validators, new NullableFunction<Compiler, Compiler>() {
|
||||
public Compiler fun(final Compiler validator) {
|
||||
return myConfiguration.isSelected(validator) ? validator : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private List<Compiler> getValidators() {
|
||||
final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
|
||||
final List<Compiler> validators = new ArrayList<Compiler>();
|
||||
validators.addAll(Arrays.asList(compilerManager.getCompilers(Validator.class)));
|
||||
for (GenericCompiler compiler : compilerManager.getCompilers(GenericCompiler.class)) {
|
||||
if (compiler.getOrderPlace() == GenericCompiler.CompileOrderPlace.VALIDATING) {
|
||||
validators.add(compiler);
|
||||
}
|
||||
}
|
||||
return validators;
|
||||
}
|
||||
|
||||
public void disposeUIResources() {
|
||||
myExcludedConfigurable.disposeUIResources();
|
||||
}
|
||||
|
||||
private void createUIComponents() {
|
||||
myValidators = new ElementsChooser<Compiler>(true) {
|
||||
@Override
|
||||
protected String getItemText(@NotNull final Compiler validator) {
|
||||
final String description = validator.getDescription();
|
||||
return description.replace(" Validator", "").replace(" validator", "");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,7 @@
|
||||
</group>
|
||||
|
||||
<group id="CompilerErrorViewPopupMenu">
|
||||
<action id="ExcludeFromValidation" class="com.intellij.compiler.options.ExcludeFromValidationAction"/>
|
||||
</group>
|
||||
|
||||
<!-- Tools -->
|
||||
|
||||
@@ -245,6 +245,8 @@
|
||||
key="java.compiler.description" bundle="messages.CompilerBundle"/>
|
||||
<configurable instance="com.intellij.compiler.options.AnnotationProcessorsConfigurable"
|
||||
id="reference.projectsettings.compiler.annotationProcessors" displayName="Annotation Processors"/>
|
||||
<configurable instance="com.intellij.compiler.options.ValidationConfigurable" id="project.validation" key="validation.display.name"
|
||||
bundle="messages.CompilerBundle" />
|
||||
<configurable instance="com.intellij.compiler.options.RmicConfigurable" id="reference.projectsettings.compiler.rmicompiler"
|
||||
key="rmi.compiler.description" bundle="messages.CompilerBundle"/>
|
||||
</projectConfigurable>
|
||||
|
||||
Reference in New Issue
Block a user