mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[compiler] Use UI DSL in JavaCompilersTab
#IDEA-334671 #IDEA-344704 Fixed GitOrigin-RevId: 5bc5529c7ae023f4039341d06dc65bbf8913b22a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a0e94a1336
commit
ff8130b4fc
@@ -1,70 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.compiler.options.JavaCompilersTab">
|
||||
<grid id="3d361" binding="myPanel" layout-manager="GridLayoutManager" row-count="5" 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="63" y="62" width="408" height="176"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="d786c" layout-manager="GridLayoutManager" row-count="1" column-count="2" 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="0" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="9fc5b" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<labelFor value="99748"/>
|
||||
<text resource-bundle="messages/JavaCompilerBundle" key="option.use.compiler.text"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="99748" class="javax.swing.JComboBox" binding="myCompiler">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<xy id="12adb" binding="myContentPanel" layout-manager="XYLayout" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="1" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</xy>
|
||||
<grid id="a6152" binding="myTargetOptionsPanel" 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="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
<vspacer id="7c703">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</vspacer>
|
||||
<component id="215c1" class="com.intellij.ui.components.JBCheckBox" binding="myCbUseReleaseOption">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<margin top="2" left="2" bottom="2" right="2"/>
|
||||
<text resource-bundle="messages/JavaCompilerBundle" key="settings.use.release.option.for.cross.compilation"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
@@ -13,12 +13,9 @@ import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.SimpleListCellRenderer;
|
||||
import com.intellij.ui.components.JBCheckBox;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -27,18 +24,12 @@ import java.util.Objects;
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
*/
|
||||
public class JavaCompilersTab extends CompositeConfigurable<Configurable> implements SearchableConfigurable, Configurable.NoScroll {
|
||||
private JPanel myPanel;
|
||||
private JPanel myContentPanel;
|
||||
private JComboBox<BackendCompiler> myCompiler;
|
||||
private JPanel myTargetOptionsPanel;
|
||||
private JBCheckBox myCbUseReleaseOption;
|
||||
private final CardLayout myCardLayout;
|
||||
public class JavaCompilersTab extends CompositeConfigurable<Configurable> implements SearchableConfigurable {
|
||||
private final JavaCompilersTabUi myUi;
|
||||
|
||||
private final Project myProject;
|
||||
private final CompilerConfigurationImpl myCompilerConfiguration;
|
||||
private final BackendCompiler myDefaultCompiler;
|
||||
private final TargetOptionsComponent myTargetLevelComponent;
|
||||
private final List<Configurable> myConfigurables;
|
||||
private BackendCompiler mySelectedCompiler;
|
||||
|
||||
@@ -46,31 +37,16 @@ public class JavaCompilersTab extends CompositeConfigurable<Configurable> implem
|
||||
myProject = project;
|
||||
myCompilerConfiguration = (CompilerConfigurationImpl)CompilerConfiguration.getInstance(project);
|
||||
myDefaultCompiler = myCompilerConfiguration.getDefaultCompiler();
|
||||
myTargetLevelComponent = new TargetOptionsComponent(project);
|
||||
|
||||
myCardLayout = new CardLayout();
|
||||
myContentPanel.setLayout(myCardLayout);
|
||||
myTargetOptionsPanel.setLayout(new BorderLayout());
|
||||
myTargetOptionsPanel.add(myTargetLevelComponent, BorderLayout.CENTER);
|
||||
|
||||
Collection<BackendCompiler> compilers = myCompilerConfiguration.getRegisteredJavaCompilers();
|
||||
myConfigurables = new ArrayList<>(compilers.size());
|
||||
for (BackendCompiler compiler : compilers) {
|
||||
Configurable configurable = compiler.createConfigurable();
|
||||
myConfigurables.add(configurable);
|
||||
JComponent component = configurable.createComponent();
|
||||
assert component != null : configurable.getClass();
|
||||
myContentPanel.add(component, compiler.getId());
|
||||
}
|
||||
|
||||
myCompiler.setModel(new DefaultComboBoxModel<>(compilers.toArray(new BackendCompiler[0])));
|
||||
myCompiler.setRenderer(SimpleListCellRenderer.create("", BackendCompiler::getPresentableName));
|
||||
myCompiler.addActionListener(e -> {
|
||||
BackendCompiler compiler = (BackendCompiler)myCompiler.getSelectedItem();
|
||||
if (compiler != null) {
|
||||
selectCompiler(compiler);
|
||||
}
|
||||
});
|
||||
myUi = new JavaCompilersTabUi(
|
||||
project,
|
||||
compilers,
|
||||
configurable -> myConfigurables.add(configurable),
|
||||
compiler -> selectCompiler(compiler)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,15 +69,15 @@ public class JavaCompilersTab extends CompositeConfigurable<Configurable> implem
|
||||
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
return myPanel;
|
||||
return myUi.getPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
return !Comparing.equal(mySelectedCompiler, myCompilerConfiguration.getDefaultCompiler()) ||
|
||||
myCbUseReleaseOption.isSelected() != myCompilerConfiguration.useReleaseOption() ||
|
||||
!Objects.equals(myTargetLevelComponent.getProjectBytecodeTarget(), myCompilerConfiguration.getProjectBytecodeTarget()) ||
|
||||
!Comparing.equal(myTargetLevelComponent.getModulesBytecodeTargetMap(), myCompilerConfiguration.getModulesBytecodeTargetMap()) ||
|
||||
myUi.useReleaseOptionCb.isSelected() != myCompilerConfiguration.useReleaseOption() ||
|
||||
!Objects.equals(myUi.targetOptionsComponent.getProjectBytecodeTarget(), myCompilerConfiguration.getProjectBytecodeTarget()) ||
|
||||
!Comparing.equal(myUi.targetOptionsComponent.getModulesBytecodeTargetMap(), myCompilerConfiguration.getModulesBytecodeTargetMap()) ||
|
||||
super.isModified();
|
||||
}
|
||||
|
||||
@@ -109,14 +85,14 @@ public class JavaCompilersTab extends CompositeConfigurable<Configurable> implem
|
||||
public void apply() throws ConfigurationException {
|
||||
try {
|
||||
myCompilerConfiguration.setDefaultCompiler(mySelectedCompiler);
|
||||
myCompilerConfiguration.setUseReleaseOption(myCbUseReleaseOption.isSelected());
|
||||
myCompilerConfiguration.setProjectBytecodeTarget(myTargetLevelComponent.getProjectBytecodeTarget());
|
||||
myCompilerConfiguration.setModulesBytecodeTargetMap(myTargetLevelComponent.getModulesBytecodeTargetMap());
|
||||
myCompilerConfiguration.setUseReleaseOption(myUi.useReleaseOptionCb.isSelected());
|
||||
myCompilerConfiguration.setProjectBytecodeTarget(myUi.targetOptionsComponent.getProjectBytecodeTarget());
|
||||
myCompilerConfiguration.setModulesBytecodeTargetMap(myUi.targetOptionsComponent.getModulesBytecodeTargetMap());
|
||||
|
||||
super.apply();
|
||||
|
||||
myTargetLevelComponent.setProjectBytecodeTargetLevel(myCompilerConfiguration.getProjectBytecodeTarget());
|
||||
myTargetLevelComponent.setModuleTargetLevels(myCompilerConfiguration.getModulesBytecodeTargetMap());
|
||||
myUi.targetOptionsComponent.setProjectBytecodeTargetLevel(myCompilerConfiguration.getProjectBytecodeTarget());
|
||||
myUi.targetOptionsComponent.setModuleTargetLevels(myCompilerConfiguration.getModulesBytecodeTargetMap());
|
||||
}
|
||||
finally {
|
||||
if (!myProject.isDefault()) {
|
||||
@@ -130,20 +106,18 @@ public class JavaCompilersTab extends CompositeConfigurable<Configurable> implem
|
||||
public void reset() {
|
||||
super.reset();
|
||||
selectCompiler(myCompilerConfiguration.getDefaultCompiler());
|
||||
myCbUseReleaseOption.setSelected(myCompilerConfiguration.useReleaseOption());
|
||||
myTargetLevelComponent.setProjectBytecodeTargetLevel(myCompilerConfiguration.getProjectBytecodeTarget());
|
||||
myTargetLevelComponent.setModuleTargetLevels(myCompilerConfiguration.getModulesBytecodeTargetMap());
|
||||
myUi.useReleaseOptionCb.setSelected(myCompilerConfiguration.useReleaseOption());
|
||||
myUi.targetOptionsComponent.setProjectBytecodeTargetLevel(myCompilerConfiguration.getProjectBytecodeTarget());
|
||||
myUi.targetOptionsComponent.setModuleTargetLevels(myCompilerConfiguration.getModulesBytecodeTargetMap());
|
||||
}
|
||||
|
||||
private void selectCompiler(BackendCompiler compiler) {
|
||||
if (compiler == null) {
|
||||
compiler = myDefaultCompiler;
|
||||
}
|
||||
myCompiler.setSelectedItem(compiler);
|
||||
myUi.compilerComboBox.setSelectedItem(compiler);
|
||||
mySelectedCompiler = compiler;
|
||||
myCardLayout.show(myContentPanel, compiler.getId());
|
||||
myContentPanel.revalidate();
|
||||
myContentPanel.repaint();
|
||||
myUi.show(compiler.getId());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.compiler.options
|
||||
|
||||
import com.intellij.compiler.impl.javaCompiler.BackendCompiler
|
||||
import com.intellij.openapi.compiler.JavaCompilerBundle
|
||||
import com.intellij.openapi.options.Configurable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.ComboBox
|
||||
import com.intellij.ui.dsl.builder.*
|
||||
import com.intellij.ui.dsl.listCellRenderer.textListCellRenderer
|
||||
import java.util.function.Consumer
|
||||
import javax.swing.JCheckBox
|
||||
|
||||
class JavaCompilersTabUi(
|
||||
project: Project,
|
||||
val compilers: Collection<BackendCompiler>,
|
||||
configurableConsumer: Consumer<Configurable>,
|
||||
val compilerSelected: Consumer<BackendCompiler>,
|
||||
) {
|
||||
|
||||
lateinit var compilerComboBox: ComboBox<BackendCompiler>
|
||||
lateinit var useReleaseOptionCb: JCheckBox
|
||||
lateinit var targetOptionsComponent: TargetOptionsComponent
|
||||
|
||||
val compilersMap = hashMapOf<String, Panel>()
|
||||
|
||||
val panel = panel {
|
||||
row(JavaCompilerBundle.message("option.use.compiler.text")) {
|
||||
compilerComboBox = comboBox(compilers, textListCellRenderer { it?.presentableName ?: "" })
|
||||
.applyToComponent {
|
||||
addActionListener {
|
||||
val compiler = compilerComboBox.getSelectedItem()
|
||||
if (compiler is BackendCompiler) compilerSelected.accept(compiler)
|
||||
}
|
||||
}
|
||||
.component
|
||||
}
|
||||
|
||||
row {
|
||||
useReleaseOptionCb = checkBox(JavaCompilerBundle.message("settings.use.release.option.for.cross.compilation"))
|
||||
.component
|
||||
}
|
||||
|
||||
row {
|
||||
targetOptionsComponent = cell(TargetOptionsComponent(project))
|
||||
.resizableColumn()
|
||||
.align(AlignX.FILL)
|
||||
.component
|
||||
}
|
||||
.bottomGap(BottomGap.MEDIUM)
|
||||
|
||||
compilers.forEach { compiler ->
|
||||
val configurable = compiler.createConfigurable()
|
||||
configurableConsumer.accept(configurable)
|
||||
|
||||
val component = configurable.createComponent()
|
||||
assert(component != null)
|
||||
val p = panel {
|
||||
row {
|
||||
cell(component!!)
|
||||
.resizableColumn()
|
||||
.align(AlignX.FILL)
|
||||
}
|
||||
.resizableRow()
|
||||
}
|
||||
|
||||
compilersMap.put(compiler.id, p)
|
||||
}
|
||||
}
|
||||
|
||||
fun show(id: String) {
|
||||
compilersMap.forEach { (compilerId, panel) ->
|
||||
panel.visible(id == compilerId)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user