package com.darkyen;

import com.intellij.openapi.components.*;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.WindowManager;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 *
 */
@State(
        name="DarkyenusTimeTracker",
        storages = {@Storage(value = StoragePathMacros.WORKSPACE_FILE, roamingType = RoamingType.DEFAULT)}
        )
public final class TimeTrackerComponent implements ProjectComponent, PersistentStateComponent<TimeTrackerState>, Configurable {

    private final Project project;
    private TimeTrackerWidget widget;

    private TimeTrackerState lastStateCache = null;

    public TimeTrackerComponent(Project project) {
        this.project = project;
    }

    @Override
    public void initComponent() {
    }

    @Override
    public void disposeComponent() {
    }

    @Override
    @NotNull
    public String getComponentName() {
        return "TimeTrackerComponent";
    }

    @Override
    public void projectOpened() {
        if (widget == null) {
            widget = new TimeTrackerWidget(project);
            if (lastStateCache != null) {
                widget.setState(lastStateCache);
                lastStateCache = null;
            }
            WindowManager.getInstance().getStatusBar(project).addWidget(widget);
        }
    }

    @Override
    public void projectClosed() {
        if (widget != null) {
            WindowManager.getInstance().getStatusBar(project).removeWidget(widget.ID());
            lastStateCache = widget.getState();
        }
    }

    @Nullable
    @Override
    public TimeTrackerState getState() {
        if (widget != null) {
            return widget.getState();
        } else if(lastStateCache != null) {
            return lastStateCache;
        } else {
            return new TimeTrackerState();
        }
    }

    @Override
    public void loadState(TimeTrackerState state) {
        if (widget != null) {
            widget.setState(state);
        } else {
            lastStateCache = state;
        }
    }

    // Configurable

    @Nls
    @Override
    public String getDisplayName() {
        return "Darkyenus Time Tracker";
    }

    @Nullable
    @Override
    public String getHelpTopic() {
        return null;
    }

    @Nullable
    @Override
    public JComponent createComponent() {
        return null;
    }

    @Override
    public boolean isModified() {
        return false;
    }

    @Override
    public void apply() throws ConfigurationException {

    }

    @Override
    public void reset() {

    }
}

@@ -61,118 +61,8 @@
 .*;%0A
-import com.intellij.openapi.options.Configurable;%0Aimport com.intellij.openapi.options.ConfigurationException;%0A
 impo
@@ -102,16 +102,16 @@
 roject;%0A
+
 import c
@@ -152,46 +152,8 @@
 er;%0A
-import org.jetbrains.annotations.Nls;%0A
 impo
@@ -238,31 +238,8 @@
 e;%0A%0A
-import javax.swing.*;%0A%0A
 /**%0A
@@ -407,16 +407,16 @@
       )%0A
+
 public f
@@ -522,22 +522,8 @@
 ate%3E
-, Configurable
  %7B%0A%0A
@@ -2066,528 +2066,7 @@
    %7D
-%0A%0A    // Configurable%0A%0A    @Nls%0A    @Override%0A    public String getDisplayName() %7B%0A        return %22Darkyenus Time Tracker%22;%0A    %7D%0A%0A    @Nullable%0A    @Override%0A    public String getHelpTopic() %7B%0A        return null;%0A    %7D%0A%0A    @Nullable%0A    @Override%0A    public JComponent createComponent() %7B%0A        return null;%0A    %7D%0A%0A    @Override%0A    public boolean isModified() %7B%0A        return false;%0A    %7D%0A%0A    @Override%0A    public void apply() throws ConfigurationException %7B%0A%0A    %7D%0A%0A    @Override%0A    public void reset() %7B%0A%0A    %7D
 %0A%7D%0A

Remove Configurable residue