<commit_before>/*(c) Copyright 2008, VersionOne, Inc. All rights reserved. (c)*/
package com.versionone.integration.idea;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.util.ui.Table;
import com.intellij.util.ui.UIUtil;
import com.versionone.common.sdk.IDataLayer;
import com.versionone.common.sdk.ApiDataLayer;
import com.versionone.common.sdk.DataLayerException;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import java.awt.*;

public class DetailsComponent implements ProjectComponent {

    private static final Logger LOG = Logger.getLogger(DetailsComponent.class);
    @NonNls
    private static final String COMPONENT_NAME = "V1.Details";
    public static final String TOOL_WINDOW_NAME = "V1Details";

    private final Project project;

    private Table table;
    private DetailsModel model;
    private TableModelListener tableChangesListener;
    private WorkspaceSettings settings;


    public DetailsComponent(Project project, WorkspaceSettings settings) {
        this.settings = settings;
        this.project = project;
    }

    public void projectOpened() {
        initToolWindow();

        TableModelListener changeListener = new TableModelListener() {
            public void tableChanged(TableModelEvent e) {
                update();
            }
        };

        ListSelectionListener selectListener = new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                int index = lsm.getMinSelectionIndex();

                //model.setWorkitem(dataLayer.getWorkitemTree().get(0));

                update();
            }
        };

        this.project.getComponent(TasksComponent.class).registerTableChangeListener(changeListener);
        this.project.getComponent(TasksComponent.class).registerTableSelectListener(selectListener);
    }

    public void projectClosed() {
        unregisterToolWindow();
    }

    public void initComponent() {
        ColorKey.createColorKey("V1_CHANGED_ROW", new Color(255, 243, 200));
    }

    public void disposeComponent() {
        // empty
    }

    @NotNull
    @NonNls
    public String getComponentName() {
        return COMPONENT_NAME;
    }

    public void registerTableListener(TableModelListener listener) {
        tableChangesListener = listener;
        if (table != null) {
            table.getModel().addTableModelListener(tableChangesListener);
        }
    }

    private void initToolWindow() {
        IDataLayer dataLayer = project.getComponent(TasksComponent.class).getDataLayer();
        JPanel contentPanel = createContentPanel(dataLayer);

//        ActionGroup actions = (ActionGroup) ActionManager.getInstance().getAction(COMPONENT_NAME);
//        ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(COMPONENT_NAME, actions, false);
//        contentPanel.add(toolbar.getComponent(), BorderLayout.LINE_START);

        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_NAME, false, ToolWindowAnchor.RIGHT);
        ContentFactory contentFactory;
        contentFactory = ContentFactory.SERVICE.getInstance();
//        contentFactory = PeerFactory.getInstance().getContentFactory();
        Content content = contentFactory.createContent(contentPanel, null, false);
        toolWindow.getContentManager().addContent(content);
    }

    public void update() {
//        if (content != null) {
//            content.setDisplayName(cfg.projectName);
//        }
        table.revalidate();<commit_msg>Throwing of exception with diagnostic message on wrong plugin version added.<commit_after>/*(c) Copyright 2008, VersionOne, Inc. All rights reserved. (c)*/
package com.versionone.integration.idea;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.editor.colors.ColorKey;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.util.ui.Table;
import com.intellij.util.ui.UIUtil;
import com.versionone.common.sdk.IDataLayer;
import com.versionone.common.sdk.ApiDataLayer;
import com.versionone.common.sdk.DataLayerException;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import java.awt.*;

public class DetailsComponent implements ProjectComponent {

    private static final Logger LOG = Logger.getLogger(DetailsComponent.class);
    @NonNls
    private static final String COMPONENT_NAME = "V1.Details";
    public static final String TOOL_WINDOW_NAME = "V1Details";

    private final Project project;

    private Table table;
    private DetailsModel model;
    private TableModelListener tableChangesListener;
    private WorkspaceSettings settings;


    public DetailsComponent(Project project, WorkspaceSettings settings) {
        this.settings = settings;
        this.project = project;
    }

    public void projectOpened() {
        initToolWindow();

        TableModelListener changeListener = new TableModelListener() {
            public void tableChanged(TableModelEvent e) {
                update();
            }
        };

        ListSelectionListener selectListener = new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                int index = lsm.getMinSelectionIndex();

                //model.setWorkitem(dataLayer.getWorkitemTree().get(0));

                update();
            }
        };

        this.project.getComponent(TasksComponent.class).registerTableChangeListener(changeListener);
        this.project.getComponent(TasksComponent.class).registerTableSelectListener(selectListener);
    }

    public void projectClosed() {
        unregisterToolWindow();
    }

    public void initComponent() {
        ColorKey.createColorKey("V1_CHANGED_ROW", new Color(255, 243, 200));
    }

    public void disposeComponent() {
        // empty
    }

    @NotNull
    @NonNls
    public String getComponentName() {
        return COMPONENT_NAME;
    }

    public void registerTableListener(TableModelListener listener) {
        tableChangesListener = listener;
        if (table != null) {
            table.getModel().addTableModelListener(tableChangesListener);
        }
    }

    private void initToolWindow() {
        final TasksComponent tasksComponent = project.getComponent(TasksComponent.class);
        if (tasksComponent == null) {
            throw new IllegalStateException("Cannot access " + TasksComponent.TOOL_WINDOW_ID + " component." +
                    " May be you use wrong versions of VersionOne plugin.");
        }
        IDataLayer dataLayer = tasksComponent.getDataLayer();
        JPanel contentPanel = createContentPanel(dataLayer);

//        ActionGroup actions = (ActionGroup) ActionManager.getInstance().getAction(COMPONENT_NAME);
//        ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(COMPONENT_NAME, actions, false);
//        contentPanel.add(toolbar.getComponent(), BorderLayout.LINE_START);

        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_NAME, false, ToolWindowAnchor.RIGHT);
        ContentFactory contentFactory;
        contentFactory = ContentFactory.SERVICE.getInstance();
//        contentFactory = PeerFactory.getInstance().getContentFactory();
        Content content = contentFactory.createContent(contentPanel, null, false);
        toolWindow.getContentManager().addContent(content);
    }

    public void update() {
//        if (content != null) {
//            content.setDisplayName(cfg.projectName);
//        }
        table.revalidate();
{'fraction_non_alphanumeric': 0.09287232852187535, 'fraction_numerical': 0.004028197381671702, 'mean_word_length': 3.4623065401897155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3224520', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2283, 'n_words': 465}