LogConfigurationPanel. Toolbar decorator.

This commit is contained in:
Evgeny Zakrevsky
2012-03-12 15:57:05 +04:00
parent f31dd9f412
commit f9922f2318
2 changed files with 100 additions and 135 deletions
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.diagnostic.logging.LogConfigurationPanel">
<grid id="57687" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="57687" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="15">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="25" y="74" width="392" height="210"/>
<xy x="25" y="74" width="410" height="222"/>
</constraints>
<properties/>
<clientProperties>
@@ -11,73 +11,38 @@
</clientProperties>
<border type="none" title-resource-bundle="messages/DiagnosticBundle" title-key="log.monitor.group"/>
<children>
<grid id="93252" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="2" bottom="0" right="2"/>
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="3" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="bb1e9" class="javax.swing.JButton" binding="myAddButton">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/DiagnosticBundle" key="log.monitor.add.button"/>
</properties>
</component>
<component id="11c0" class="javax.swing.JButton" binding="myRemoveButton">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="messages/DiagnosticBundle" key="log.monitor.remove.button"/>
</properties>
</component>
<vspacer id="ab230">
<constraints>
<grid row="3" 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="6c26a" class="javax.swing.JButton" binding="myEditButton" default-binding="true">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Edit"/>
</properties>
</component>
</children>
</grid>
<grid id="faa06" binding="myScrollPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<component id="37d5" class="com.intellij.ui.components.JBCheckBox" binding="myRedirectOutputCb" default-binding="true">
<grid id="a8add" 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="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<margin top="7" left="3" bottom="2" right="3"/>
<text value="&amp;Save console output to file:"/>
</properties>
</component>
<hspacer id="9d463">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="c07c6" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myOutputFile">
<constraints>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" 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="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<border type="none"/>
<children>
<component id="37d5" class="com.intellij.ui.components.JBCheckBox" binding="myRedirectOutputCb" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Save console output to file:"/>
</properties>
</component>
<component id="c07c6" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myOutputFile">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -20,6 +20,7 @@ import com.intellij.diagnostic.DiagnosticBundle;
import com.intellij.execution.configurations.LogFileOptions;
import com.intellij.execution.configurations.PredefinedLogFile;
import com.intellij.execution.configurations.RunConfigurationBase;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
@@ -28,9 +29,7 @@ import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.BooleanTableCellRenderer;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TableUtil;
import com.intellij.ui.*;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.table.TableView;
import com.intellij.util.ui.AbstractTableCellEditor;
@@ -40,8 +39,6 @@ import com.intellij.util.ui.ListTableModel;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.ActionEvent;
@@ -59,10 +56,7 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
private final TableView<LogFileOptions> myFilesTable;
private final ListTableModel<LogFileOptions> myModel;
private JPanel myWholePanel;
private JButton myAddButton;
private JButton myRemoveButton;
private JPanel myScrollPanel;
private JButton myEditButton;
private JBCheckBox myRedirectOutputCb;
private TextFieldWithBrowseButton myOutputFile;
private final Map<LogFileOptions, PredefinedLogFile> myLog2Predefined = new HashMap<LogFileOptions, PredefinedLogFile>();
@@ -92,64 +86,68 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
myFilesTable.setShowHorizontalLines(false);
myFilesTable.setShowVerticalLines(false);
myFilesTable.setIntercellSpacing(new Dimension(0, 0));
myAddButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ArrayList<LogFileOptions> newList = new ArrayList<LogFileOptions>(myModel.getItems());
LogFileOptions newOptions = new LogFileOptions("", "", true, true, false);
if (showEditorDialog(newOptions)) {
newList.add(newOptions);
myModel.setItems(newList);
int index = myModel.getRowCount() - 1;
myModel.fireTableRowsInserted(index, index);
myFilesTable.setRowSelectionInterval(index, index);
myScrollPanel.add(
ToolbarDecorator.createDecorator(myFilesTable)
.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
ArrayList<LogFileOptions> newList = new ArrayList<LogFileOptions>(myModel.getItems());
LogFileOptions newOptions = new LogFileOptions("", "", true, true, false);
if (showEditorDialog(newOptions)) {
newList.add(newOptions);
myModel.setItems(newList);
int index = myModel.getRowCount() - 1;
myModel.fireTableRowsInserted(index, index);
myFilesTable.setRowSelectionInterval(index, index);
}
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.stopEditing(myFilesTable);
final int[] selected = myFilesTable.getSelectedRows();
if (selected == null || selected.length == 0) return;
for (int i = selected.length - 1; i >= 0; i--) {
myModel.removeRow(selected[i]);
}
for (int i = selected.length - 1; i >= 0; i--) {
int idx = selected[i];
myModel.fireTableRowsDeleted(idx, idx);
}
int selection = selected[0];
if (selection >= myModel.getRowCount()) {
selection = myModel.getRowCount() - 1;
}
if (selection >= 0) {
myFilesTable.setRowSelectionInterval(selection, selection);
}
myFilesTable.requestFocus();
}
}
});
myRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TableUtil.stopEditing(myFilesTable);
final int[] selected = myFilesTable.getSelectedRows();
if (selected == null || selected.length == 0) return;
for (int i = selected.length - 1; i >= 0; i--) {
myModel.removeRow(selected[i]);
}).setEditAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final int selectedRow = myFilesTable.getSelectedRow();
final LogFileOptions selectedOptions = myFilesTable.getSelectedObject();
showEditorDialog(selectedOptions);
myModel.fireTableDataChanged();
myFilesTable.setRowSelectionInterval(selectedRow, selectedRow);
}
for (int i = selected.length - 1; i >= 0; i--) {
int idx = selected[i];
myModel.fireTableRowsDeleted(idx, idx);
}).setRemoveActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return myFilesTable.getSelectedRowCount() >= 1 &&
!myLog2Predefined.containsKey(myFilesTable.getSelectedObject());
}
int selection = selected[0];
if (selection >= myModel.getRowCount()) {
selection = myModel.getRowCount() - 1;
}).setEditActionUpdater(new AnActionButtonUpdater() {
@Override
public boolean isEnabled(AnActionEvent e) {
return myFilesTable.getSelectedRowCount() >= 1 &&
!myLog2Predefined.containsKey(myFilesTable.getSelectedObject()) &&
myFilesTable.getSelectedObject() != null;
}
if (selection >= 0) {
myFilesTable.setRowSelectionInterval(selection, selection);
}
myFilesTable.requestFocus();
}
});
myRemoveButton.setEnabled(false);
myFilesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
final boolean enabled = myFilesTable.getSelectedRowCount() >= 1 &&
!myLog2Predefined.containsKey(myFilesTable.getSelectedObject());
myRemoveButton.setEnabled(enabled);
myEditButton.setEnabled(enabled && myFilesTable.getSelectedObject() != null);
}
});
myEditButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final int selectedRow = myFilesTable.getSelectedRow();
final LogFileOptions selectedOptions = myFilesTable.getSelectedObject();
showEditorDialog(selectedOptions);
myModel.fireTableDataChanged();
myFilesTable.setRowSelectionInterval(selectedRow, selectedRow);
}
});
myEditButton.setEnabled(false);
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myFilesTable);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
myScrollPanel.add(scrollPane, BorderLayout.CENTER);
}).disableUpDownActions().createPanel(), BorderLayout.CENTER);
myWholePanel.setPreferredSize(new Dimension(-1, 150));
myOutputFile.addBrowseFolderListener("Choose File to Save Console Output", "Console output would be saved to the specified file", null,
FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(),
@@ -181,7 +179,7 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
final LogFileOptions options = configurationBase.getOptionsForPredefinedLogFile(predefined);
if (LogFileOptions.areEqual(item, options)) {
newItems.add(item);
}
}
else {
changed = true;
myLog2Predefined.remove(item);
@@ -219,7 +217,8 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
ArrayList<LogFileOptions> list = new ArrayList<LogFileOptions>();
final ArrayList<LogFileOptions> logFiles = configuration.getLogFiles();
for (LogFileOptions setting : logFiles) {
list.add(new LogFileOptions(setting.getName(), setting.getPathPattern(), setting.isEnabled(), setting.isSkipContent(), setting.isShowAll()));
list.add(
new LogFileOptions(setting.getName(), setting.getPathPattern(), setting.isEnabled(), setting.isSkipContent(), setting.isShowAll()));
}
myLog2Predefined.clear();
myUnresolvedPredefined.clear();
@@ -250,9 +249,9 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
for (int i = 0; i < myModel.getRowCount(); i++) {
LogFileOptions options = (LogFileOptions)myModel.getValueAt(i, 1);
if (Comparing.equal(options.getPathPattern(),"")){
continue;
}
if (Comparing.equal(options.getPathPattern(), "")) {
continue;
}
final Boolean checked = (Boolean)myModel.getValueAt(i, 0);
final Boolean skipped = (Boolean)myModel.getValueAt(i, 2);
final PredefinedLogFile predefined = myLog2Predefined.get(options);
@@ -260,7 +259,8 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
configuration.addPredefinedLogFile(new PredefinedLogFile(predefined.getId(), options.isEnabled()));
}
else {
configuration.addLogFile(options.getPathPattern(), options.getName(), checked.booleanValue(), skipped.booleanValue(), options.isShowAll());
configuration
.addLogFile(options.getPathPattern(), options.getName(), checked.booleanValue(), skipped.booleanValue(), options.isShowAll());
}
}
for (PredefinedLogFile logFile : myUnresolvedPredefined) {
@@ -279,7 +279,7 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
protected void disposeEditor() {
}
private static boolean showEditorDialog(@NotNull LogFileOptions options){
private static boolean showEditorDialog(@NotNull LogFileOptions options) {
EditLogPatternDialog dialog = new EditLogPatternDialog();
dialog.init(options.getName(), options.getPathPattern(), options.isShowAll());
dialog.show();
@@ -320,18 +320,18 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
public TableCellEditor getEditor(final LogFileOptions item) {
return new LogFileCellEditor(item);
}
}
public void setValue(final LogFileOptions o, final LogFileOptions aValue) {
if (aValue != null) {
if (!o.getName().equals(aValue.getName()) || !o.getPathPattern().equals(aValue.getPathPattern())
|| o.isShowAll() != aValue.isShowAll()) {
|| o.isShowAll() != aValue.isShowAll()) {
myLog2Predefined.remove(o);
}
}
o.setName(aValue.getName());
o.setShowAll(aValue.isShowAll());
o.setPathPattern(aValue.getPathPattern());
}
}
}
public boolean isCellEditable(final LogFileOptions o) {
@@ -356,13 +356,13 @@ public class LogConfigurationPanel<T extends RunConfigurationBase> extends Setti
return true;
}
public void setValue(LogFileOptions element, Boolean checked){
public void setValue(LogFileOptions element, Boolean checked) {
final PredefinedLogFile predefinedLogFile = myLog2Predefined.get(element);
if (predefinedLogFile != null) {
predefinedLogFile.setEnabled(checked.booleanValue());
}
}
element.setEnable(checked.booleanValue());
}
}
}
private class MyIsSkipColumnInfo extends ColumnInfo<LogFileOptions, Boolean> {