IDE errors dialog: show label if report will include attachment(s) (IDEA-78964)

This commit is contained in:
kirill.safonov
2011-12-18 18:54:43 +04:00
parent 8cb72dd8ba
commit dcf5dfffb7
6 changed files with 134 additions and 8 deletions
@@ -0,0 +1,42 @@
/*
* Copyright 2000-2011 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.diagnostic;
import com.intellij.diagnostic.errordialog.Attachment;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.diagnostic.Logger;
import java.awt.event.InputEvent;
@SuppressWarnings({"HardCodedStringLiteral"})
public class DropAnErrorWithAttachmentsAction extends AnAction {
public DropAnErrorWithAttachmentsAction() {
super("Drop an error with attachments", "Hold down SHIFT for multiple attachments", null);
}
public void actionPerformed(AnActionEvent e) {
final boolean multipleAttachments = (e.getModifiers() & InputEvent.SHIFT_MASK) != 0;
Attachment[] attachments;
if (multipleAttachments) {
attachments = new Attachment[]{new Attachment("first.txt", "first content"), new Attachment("second.txt", "second content")};
}
else {
attachments = new Attachment[]{new Attachment("attachment.txt", "content")};
}
Logger.getInstance("test (with attachments)").error(LogMessageEx.createEvent("test", "test details", attachments));
}
}
@@ -38,6 +38,7 @@ import com.intellij.ui.HyperlinkLabel;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.util.Consumer;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
@@ -58,7 +59,7 @@ import java.util.List;
public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListener, TypeSafeDataProvider {
private static final Logger LOG = Logger.getInstance(IdeErrorsDialog.class.getName());
public static final boolean INTERNAL_MODE = ApplicationManagerEx.getApplicationEx().isInternal();
public static final boolean INTERNAL_MODE = false; //ApplicationManagerEx.getApplicationEx().isInternal();
@NonNls private static final String ACTIVE_TAB_OPTION = IdeErrorsDialog.class.getName() + "activeTab";
public static DataKey<String> CURRENT_TRACE_KEY = DataKey.create("current_stack_trace_key");
public static final int COMPONENTS_WIDTH = 670;
@@ -74,6 +75,8 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene
private JPanel myCredentialsPanel;
private HyperlinkLabel myCredentialsLabel;
private JPanel myForeignPluginWarningPanel;
private JPanel myAttachmentWarningPanel;
private HyperlinkLabel myAttachmentWarningLabel;
private int myIndex = 0;
private final List<ArrayList<AbstractMessage>> myMergedMessages = new ArrayList<ArrayList<AbstractMessage>>();
@@ -246,6 +249,11 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene
myTabs.addTab(DiagnosticBundle.message("error.details.tab.title"), myDetailsTabForm.getContentPane());
myAttachmentsTabForm = new AttachmentsTabForm();
myAttachmentsTabForm.addInclusionListener(new ChangeListener() {
public void stateChanged(final ChangeEvent e) {
updateAttachmentWarning(getSelectedMessage());
}
});
int activeTabIndex = Integer.parseInt(PropertiesComponent.getInstance().getValue(ACTIVE_TAB_OPTION, "0"));
if (activeTabIndex >= myTabs.getTabCount() || activeTabIndex < 0) {
@@ -286,6 +294,16 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene
}
});
myAttachmentWarningLabel.setIcon(UIUtil.getBalloonWarningIcon());
myAttachmentWarningLabel.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
myTabs.setSelectedIndex(myTabs.indexOfComponent(myAttachmentsTabForm.getContentPane()));
myAttachmentsTabForm.selectFirstIncludedAttachment();
}
}
});
return myContentPane;
}
@@ -359,6 +377,7 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene
final AbstractMessage message = getSelectedMessage();
updateInfoLabel(message);
updateCredentialsPane(message);
updateAttachmentWarning(message);
myDisableLink.setVisible(canDisablePlugin(message));
updateForeignPluginLabel(message != null ? message : null);
updateTabs();
@@ -370,6 +389,29 @@ public class IdeErrorsDialog extends DialogWrapper implements MessagePoolListene
}
}
private void updateAttachmentWarning(final AbstractMessage message) {
final List<Attachment> includedAttachments;
if (message instanceof LogMessageEx &&
!(includedAttachments = ContainerUtil.filter(((LogMessageEx)message).getAttachments(), new Condition<Attachment>() {
public boolean value(final Attachment attachment) {
return attachment.isIncluded();
}
})).isEmpty()) {
myAttachmentWarningPanel.setVisible(true);
if (includedAttachments.size() == 1) {
myAttachmentWarningLabel.setHtmlText(
DiagnosticBundle.message("diagnostic.error.report.include.attachment.warning", includedAttachments.get(0).getName()));
}
else {
myAttachmentWarningLabel.setHtmlText(
DiagnosticBundle.message("diagnostic.error.report.include.attachments.warning", includedAttachments.size()));
}
}
else {
myAttachmentWarningPanel.setVisible(false);
}
}
private static boolean canDisablePlugin(AbstractMessage message) {
if (message == null) {
return false;
@@ -4,10 +4,13 @@ import com.intellij.diagnostic.DiagnosticBundle;
import com.intellij.ide.plugins.InstalledPluginsTableModel;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.table.TableView;
import com.intellij.util.EventDispatcher;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.ListTableModel;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
@@ -23,6 +26,7 @@ public class AttachmentsTabForm {
private JPanel myContentPane;
private TableView<Attachment> myTable;
private LabeledTextComponent myFileTextArea;
private final EventDispatcher<ChangeListener> myInclusionEventDispatcher = EventDispatcher.create(ChangeListener.class);
private final ColumnInfo<Attachment, Boolean> ENABLED_COLUMN =
new ColumnInfo<Attachment, Boolean>(DiagnosticBundle.message("error.dialog.attachment.include.column.title")) {
@@ -49,6 +53,7 @@ public class AttachmentsTabForm {
@Override
public void setValue(Attachment attachment, Boolean value) {
attachment.setIncluded(value);
myInclusionEventDispatcher.getMulticaster().stateChanged(new ChangeEvent(attachment));
}
};
@@ -110,4 +115,18 @@ public class AttachmentsTabForm {
public JPanel getContentPane() {
return myContentPane;
}
public void addInclusionListener(ChangeListener listener) {
myInclusionEventDispatcher.addListener(listener);
}
public void selectFirstIncludedAttachment() {
final List items = ((ListTableModel)myTable.getModel()).getItems();
for (Object item : items) {
if (((Attachment)item).isIncluded()) {
myTable.setSelection(Collections.singleton((Attachment)item));
break;
}
}
}
}
@@ -90,17 +90,37 @@
<border type="none"/>
<children/>
</grid>
<grid id="3eb3d" binding="myCredentialsPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<grid id="16a45" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="South"/>
<properties/>
<border type="empty">
<size top="5" left="0" bottom="0" right="0"/>
</border>
<border type="none"/>
<children>
<component id="64a8b" class="com.intellij.ui.HyperlinkLabel" binding="myCredentialsLabel">
<constraints border-constraint="East"/>
<grid id="3eb3d" binding="myCredentialsPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="North"/>
<properties/>
</component>
<border type="empty">
<size top="5" left="0" bottom="0" right="0"/>
</border>
<children>
<component id="64a8b" class="com.intellij.ui.HyperlinkLabel" binding="myCredentialsLabel">
<constraints border-constraint="East"/>
<properties/>
</component>
</children>
</grid>
<grid id="4f91d" binding="myAttachmentWarningPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="South"/>
<properties/>
<border type="empty">
<size top="5" left="0" bottom="0" right="0"/>
</border>
<children>
<component id="23d84" class="com.intellij.ui.HyperlinkLabel" binding="myAttachmentWarningLabel">
<constraints border-constraint="East"/>
<properties/>
</component>
</children>
</grid>
</children>
</grid>
</children>
@@ -90,3 +90,5 @@ error.dialog.attachment.path.column.title=Path
error.dialog.attachment.include.column.title=Include
error.attachments.tab.title=Attachments
error.dialog.filecontent.title=File content
diagnostic.error.report.include.attachment.warning=Report will include attachment: ''<a>{0}</a>''.
diagnostic.error.report.include.attachments.warning=Report will include <a>{0} attachments</a>.
@@ -485,6 +485,7 @@
<group id="Internal" text="Internal Actions" internal="true" popup="true">
<group id="Internal.Errors" popup="true" text="Exceptions">
<action id="DropAnError" internal="true" class="com.intellij.diagnostic.DropAnErrorAction"/>
<action id="DropAnErrorWithAttachments" internal="true" class="com.intellij.diagnostic.DropAnErrorWithAttachmentsAction"/>
<action id="DropAnOutOfMemoryError" internal="true" class="com.intellij.diagnostic.DropAnOutOfMemoryErrorAction"/>
<action id="DropAnOutOfPermGenMemoryError" internal="true" class="com.intellij.diagnostic.DropAnOutOfPermGenMemoryErrorAction"/>
</group>