Package org.twodividedbyzero.idea.findbugs.actions

Source Code of org.twodividedbyzero.idea.findbugs.actions.ScrollToSource

/*
* Copyright 2008-2013 Andre Pfeiler
*
* This file is part of FindBugs-IDEA.
*
* FindBugs-IDEA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* FindBugs-IDEA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with FindBugs-IDEA.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.twodividedbyzero.idea.findbugs.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import org.twodividedbyzero.idea.findbugs.core.FindBugsPlugin;
import org.twodividedbyzero.idea.findbugs.gui.toolwindow.view.ToolWindowPanel;
import org.twodividedbyzero.idea.findbugs.preferences.FindBugsPreferences;


/**
* $Date: 2013-12-05 08:09:56 -0600 (Thu, 05 Dec 2013) $
*
* @author Andre Pfeiler<andrep@twodividedbyzero.org>
* @version $Revision: 257 $
* @since 0.0.1
*/
public class ScrollToSource extends BaseToggleAction {


  @Override
  public boolean isSelected(final AnActionEvent event) {
    final Project project = DataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) {
      return false;
    }

    final FindBugsPlugin findBugsPlugin = project.getComponent(FindBugsPlugin.class);
    if (findBugsPlugin == null) {
      throw new IllegalStateException("Couldn't get findbugs plugin");
    }

    final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(getPluginInterface(project).getInternalToolWindowId());

    // toggle value
    final Content content = toolWindow.getContentManager().getContent(0);
    if (content != null) {
      final ToolWindowPanel panel = (ToolWindowPanel) content.getComponent();
      final FindBugsPreferences preferences = getPluginInterface(project).getPreferences();
      final boolean isEnabled = panel.getBugTreePanel().isScrollToSource();
      final boolean enabled = preferences.getBooleanProperty(FindBugsPreferences.TOOLWINDOW_SCROLL_TO_SOURCE, isEnabled);
      if(enabled != isEnabled) {
        panel.getBugTreePanel().setScrollToSource(enabled);
      }
      return enabled;
    }

    return false;
  }


  @Override
  public void setSelected(final AnActionEvent event, final boolean selected) {
    final Project project = DataKeys.PROJECT.getData(event.getDataContext());
    if (project == null) {
      return;
    }

    final FindBugsPlugin findBugsPlugin = project.getComponent(FindBugsPlugin.class);
    if (findBugsPlugin == null) {
      throw new IllegalStateException("Couldn't get findbugs plugin");
    }

    final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(getPluginInterface(project).getInternalToolWindowId());

    // toggle value
    final Content content = toolWindow.getContentManager().getContent(0);
    if (content != null) {
      final ToolWindowPanel panel = (ToolWindowPanel) content.getComponent();
      final FindBugsPreferences preferences = getPluginInterface(project).getPreferences();
      preferences.setProperty(FindBugsPreferences.TOOLWINDOW_SCROLL_TO_SOURCE, selected);
      panel.getBugTreePanel().setScrollToSource(selected);
    }
  }

}
TOP

Related Classes of org.twodividedbyzero.idea.findbugs.actions.ScrollToSource

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.