mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
AntArtifactPropertiesEditor. Toolbar decorator.
This commit is contained in:
+5
-61
@@ -42,74 +42,18 @@
|
||||
<grid row="2" 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>
|
||||
<grid id="1a993" binding="myPropertiesPanel" 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"/>
|
||||
<grid id="1a993" binding="myPropertiesPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="1" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="1" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="250"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<clientProperties>
|
||||
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
|
||||
</clientProperties>
|
||||
<border type="none" title="Properties"/>
|
||||
<children>
|
||||
<grid id="25699" 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="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<scrollpane id="eb376" class="com.intellij.ui.components.JBScrollPane">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="f2d63" class="com.intellij.ui.table.JBTable" binding="myPropertiesTable">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<preferredScrollableViewportSize width="350" height="200"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="c5a2a" layout-manager="GridLayoutManager" row-count="3" 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="1" 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>
|
||||
<component id="3370" class="javax.swing.JButton" binding="myAddButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Add"/>
|
||||
</properties>
|
||||
</component>
|
||||
<vspacer id="4ebaf">
|
||||
<constraints>
|
||||
<grid row="2" 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="ada4f" class="javax.swing.JButton" binding="myRemoveButton" default-binding="true">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="&Remove"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
|
||||
+79
-30
@@ -21,20 +21,23 @@ import com.intellij.lang.ant.config.AntConfiguration;
|
||||
import com.intellij.lang.ant.config.impl.BuildFileProperty;
|
||||
import com.intellij.lang.ant.config.impl.TargetChooserDialog;
|
||||
import com.intellij.lang.ant.config.impl.configuration.UIPropertyBinding;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.ui.FixedSizeButton;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.packaging.ui.ArtifactEditorContext;
|
||||
import com.intellij.packaging.ui.ArtifactPropertiesEditor;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.table.JBTable;
|
||||
import com.intellij.util.NewInstanceFactory;
|
||||
import com.intellij.util.config.ListProperty;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ColumnInfo;
|
||||
import com.intellij.util.ui.ListTableModel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
@@ -45,32 +48,34 @@ import java.util.List;
|
||||
*/
|
||||
public class AntArtifactPropertiesEditor extends ArtifactPropertiesEditor {
|
||||
private static final ListProperty<BuildFileProperty> ANT_PROPERTIES = ListProperty.create("ant-properties");
|
||||
private static final ColumnInfo<BuildFileProperty, String> NAME_COLUMN = new ColumnInfo<BuildFileProperty, String>(AntBundle.message("edit.ant.properties.name.column.name")) {
|
||||
public String valueOf(BuildFileProperty buildFileProperty) {
|
||||
return buildFileProperty.getPropertyName();
|
||||
}
|
||||
private static final ColumnInfo<BuildFileProperty, String> NAME_COLUMN =
|
||||
new ColumnInfo<BuildFileProperty, String>(AntBundle.message("edit.ant.properties.name.column.name")) {
|
||||
public String valueOf(BuildFileProperty buildFileProperty) {
|
||||
return buildFileProperty.getPropertyName();
|
||||
}
|
||||
|
||||
public boolean isCellEditable(BuildFileProperty buildFileProperty) {
|
||||
return USER_PROPERTY_CONDITION.value(buildFileProperty);
|
||||
}
|
||||
public boolean isCellEditable(BuildFileProperty buildFileProperty) {
|
||||
return USER_PROPERTY_CONDITION.value(buildFileProperty);
|
||||
}
|
||||
|
||||
public void setValue(BuildFileProperty buildFileProperty, String name) {
|
||||
buildFileProperty.setPropertyName(name);
|
||||
}
|
||||
};
|
||||
private static final ColumnInfo<BuildFileProperty, String> VALUE_COLUMN = new ColumnInfo<BuildFileProperty, String>(AntBundle.message("edit.ant.properties.value.column.name")) {
|
||||
public boolean isCellEditable(BuildFileProperty buildFileProperty) {
|
||||
return USER_PROPERTY_CONDITION.value(buildFileProperty);
|
||||
}
|
||||
public void setValue(BuildFileProperty buildFileProperty, String name) {
|
||||
buildFileProperty.setPropertyName(name);
|
||||
}
|
||||
};
|
||||
private static final ColumnInfo<BuildFileProperty, String> VALUE_COLUMN =
|
||||
new ColumnInfo<BuildFileProperty, String>(AntBundle.message("edit.ant.properties.value.column.name")) {
|
||||
public boolean isCellEditable(BuildFileProperty buildFileProperty) {
|
||||
return USER_PROPERTY_CONDITION.value(buildFileProperty);
|
||||
}
|
||||
|
||||
public String valueOf(BuildFileProperty buildFileProperty) {
|
||||
return buildFileProperty.getPropertyValue();
|
||||
}
|
||||
public String valueOf(BuildFileProperty buildFileProperty) {
|
||||
return buildFileProperty.getPropertyValue();
|
||||
}
|
||||
|
||||
public void setValue(BuildFileProperty buildFileProperty, String value) {
|
||||
buildFileProperty.setPropertyValue(value);
|
||||
}
|
||||
};
|
||||
public void setValue(BuildFileProperty buildFileProperty, String value) {
|
||||
buildFileProperty.setPropertyValue(value);
|
||||
}
|
||||
};
|
||||
private static final ColumnInfo[] PROPERTY_COLUMNS = new ColumnInfo[]{NAME_COLUMN, VALUE_COLUMN};
|
||||
private static final Condition<BuildFileProperty> USER_PROPERTY_CONDITION = new Condition<BuildFileProperty>() {
|
||||
@Override
|
||||
@@ -84,8 +89,6 @@ public class AntArtifactPropertiesEditor extends ArtifactPropertiesEditor {
|
||||
private JCheckBox myRunTargetCheckBox;
|
||||
private FixedSizeButton mySelectTargetButton;
|
||||
private JBTable myPropertiesTable;
|
||||
private JButton myAddButton;
|
||||
private JButton myRemoveButton;
|
||||
private JPanel myPropertiesPanel;
|
||||
private AntBuildTarget myTarget;
|
||||
private final boolean myPostProcessing;
|
||||
@@ -111,10 +114,59 @@ public class AntArtifactPropertiesEditor extends ArtifactPropertiesEditor {
|
||||
}
|
||||
});
|
||||
|
||||
myPropertiesTable = new JBTable();
|
||||
UIPropertyBinding.Composite binding = new UIPropertyBinding.Composite();
|
||||
myBinding = binding.bindList(myPropertiesTable, PROPERTY_COLUMNS, ANT_PROPERTIES);
|
||||
myBinding.addAddFacility(myAddButton, NewInstanceFactory.fromClass(BuildFileProperty.class));
|
||||
myBinding.addRemoveFacility(myRemoveButton, USER_PROPERTY_CONDITION);
|
||||
myPropertiesPanel.add(
|
||||
ToolbarDecorator.createDecorator(myPropertiesTable)
|
||||
.setAddAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
ListTableModel<BuildFileProperty> model = (ListTableModel<BuildFileProperty>)myPropertiesTable.getModel();
|
||||
if (myPropertiesTable.isEditing() && !myPropertiesTable.getCellEditor().stopCellEditing()) {
|
||||
return;
|
||||
}
|
||||
BuildFileProperty item = new BuildFileProperty();
|
||||
ArrayList<BuildFileProperty> items = new ArrayList<BuildFileProperty>(model.getItems());
|
||||
items.add(item);
|
||||
model.setItems(items);
|
||||
int newIndex = model.indexOf(item);
|
||||
ListSelectionModel selectionModel = myPropertiesTable.getSelectionModel();
|
||||
selectionModel.clearSelection();
|
||||
selectionModel.setSelectionInterval(newIndex, newIndex);
|
||||
ColumnInfo[] columns = model.getColumnInfos();
|
||||
for (int i = 0; i < columns.length; i++) {
|
||||
ColumnInfo column = columns[i];
|
||||
if (column.isCellEditable(item)) {
|
||||
myPropertiesTable.requestFocusInWindow();
|
||||
myPropertiesTable.editCellAt(newIndex, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}).setRemoveAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
TableUtil.removeSelectedItems(myPropertiesTable);
|
||||
}
|
||||
}).setRemoveActionUpdater(new AnActionButtonUpdater() {
|
||||
@Override
|
||||
public boolean isEnabled(AnActionEvent e) {
|
||||
final ListSelectionModel selectionModel = myPropertiesTable.getSelectionModel();
|
||||
ListTableModel<BuildFileProperty> model = (ListTableModel<BuildFileProperty>)myPropertiesTable.getModel();
|
||||
boolean enable = false;
|
||||
if (!selectionModel.isSelectionEmpty()) {
|
||||
enable = true;
|
||||
for (int i : myPropertiesTable.getSelectedRows()) {
|
||||
if (AntArtifactProperties.isPredefinedProperty(model.getItems().get(i).getPropertyName())) {
|
||||
enable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return enable;
|
||||
}
|
||||
}).disableUpDownActions().createPanel(), BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
private void selectTarget() {
|
||||
@@ -135,9 +187,6 @@ public class AntArtifactPropertiesEditor extends ArtifactPropertiesEditor {
|
||||
}
|
||||
final boolean enabled = myTarget != null && myRunTargetCheckBox.isSelected();
|
||||
UIUtil.setEnabled(myPropertiesPanel, enabled, true);
|
||||
if (enabled) {
|
||||
myBinding.updateRemoveButton(myRemoveButton, USER_PROPERTY_CONDITION);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTabName() {
|
||||
|
||||
Reference in New Issue
Block a user