org.codinjutsu.tools.nosql.commons.view.ErrorPanel.java Source code

Java tutorial

Introduction

Here is the source code for org.codinjutsu.tools.nosql.commons.view.ErrorPanel.java

Source

/*
 * Copyright (c) 2015 David Boissier
 *
 * 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 org.codinjutsu.tools.nosql.commons.view;

import com.intellij.openapi.ui.Messages;
import com.intellij.ui.HoverHyperlinkLabel;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.JBLabel;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.awt.*;

public class ErrorPanel extends JPanel {

    public ErrorPanel(final Exception ex) {
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        JBLabel comp = new JBLabel("Error during query execution:");
        comp.setForeground(JBColor.RED);
        add(comp);
        final HoverHyperlinkLabel hoverHyperlinkLabel = new HoverHyperlinkLabel("more detail...");
        hoverHyperlinkLabel.addHyperlinkListener(new HyperlinkListener() {
            @Override
            public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
                if (hyperlinkEvent.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                    Messages.showErrorDialog(ex.toString(), "Error During Query Execution");
                }
            }
        });
        add(Box.createRigidArea(new Dimension(10, 10)));
        add(hoverHyperlinkLabel);

    }
}