/*
 * Copyright (C) 2019 Stefan Zeller
 *
 * 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 ch.docksnet.rgraph.toolwindow;

import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

public class ReferenceToolWindow implements ToolWindowFactory {

    public static final String ID = "Package References";

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();

        {
            ReferenceListToolWindow referenceListToolWindow = ServiceManager.getService(project, ProjectService.class)
                    .getSamePackageReferences();
            Content content = contentFactory.createContent(referenceListToolWindow.getContent(), referenceListToolWindow.getName(), false);
            toolWindow.getContentManager().addContent(content);
        }

        {
            ReferenceListToolWindow referenceListToolWindow = ServiceManager.getService(project, ProjectService.class)
                    .getSameHierarchieReferences();
            Content content = contentFactory.createContent(referenceListToolWindow.getContent(), referenceListToolWindow.getName(), false);
            toolWindow.getContentManager().addContent(content);
        }

        {
            ReferenceListToolWindow referenceListToolWindow = ServiceManager.getService(project, ProjectService.class)
                    .getOtherHierarchieReferences();
            Content content = contentFactory.createContent(referenceListToolWindow.getContent(), referenceListToolWindow.getName(), false);
            toolWindow.getContentManager().addContent(content);
        }
    }

    @Override
    public void init(ToolWindow window) {

    }

    @Override
    public boolean shouldBeAvailable(@NotNull Project project) {
        return true;
    }

    @Override
    public boolean isDoNotActivateOnStart() {
        return true;
    }
}

@@ -1292,71 +1292,42 @@
     
-%7B%0A            ReferenceListToolWindow referenceListToolWindow =
+create(toolWindow, contentFactory,
  Ser
@@ -1379,37 +1379,16 @@
 e.class)
-%0A                    
 .getSame
@@ -1398,32 +1398,33 @@
 kageReferences()
+)
 ;%0A            Co
@@ -1421,286 +1421,174 @@
     
-    Content content = contentFactory.createContent(referenceListToolWindow.getContent(), referenceListToolWindow
+create(toolWindow, contentFactory, ServiceManager.getService(project, ProjectService.class)
 .get
-Name(), false);%0A            toolWindow.getContentManager().addContent(content);%0A        %7D%0A%0A        %7B%0A            ReferenceListToolWindow referenceListToolWindow =
+SameHierarchieReferences());%0A        create(toolWindow, contentFactory,
  Ser
@@ -1644,37 +1644,17 @@
 ass)
-%0A                    .getSame
+.getOther
 Hier
@@ -1675,161 +1675,61 @@
 es()
+)
 ;%0A    
+%7D%0A%0A
     
-    Content content = contentFactory.createContent(referenceListToolWindow.getContent(), referenceListToolWindow.getName(), false);%0A           
+private void create(@NotNull ToolWindow
  too
@@ -1739,247 +1739,75 @@
 ndow
-.get
+, 
 Content
-Manager().addContent(content);%0A        %7D%0A%0A        %7B%0A            ReferenceListToolWindow referenceListToolWindow = ServiceManager.getService(project, ProjectService.class)%0A                    .getOtherHierarchieReferences();%0A    
+Factory contentFactory, ReferenceListToolWindow window) %7B%0A
     
@@ -1857,34 +1857,17 @@
 Content(
-referenceListToolW
+w
 indow.ge
@@ -1882,26 +1882,9 @@
 (), 
-referenceListToolW
+w
 indo
@@ -1904,20 +1904,16 @@
 false);%0A
-    
         
@@ -1968,18 +1968,8 @@
 t);%0A
-        %7D%0A
     

clean up