Package com.intellij.openapi.graph.builder.actions

Source Code of com.intellij.openapi.graph.builder.actions.ShowEdgeLabels

/*
* Copyright 2000-2006 JetBrains s.r.o.
*
* 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.
*
*/

/*
* Created by IntelliJ IDEA.
* User: Sergey.Vasiliev
* Date: Sep 1, 2006
* Time: 4:02:06 PM
*/
package com.intellij.openapi.graph.builder.actions;

import com.intellij.openapi.graph.view.Graph2D;
import com.intellij.openapi.graph.builder.components.BasicGraphPresentationModel;
import com.intellij.openapi.graph.builder.GraphBuilder;
import com.intellij.openapi.graph.builder.GraphPresentationModel;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import com.intellij.idea.ActionsBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ShowEdgeLabels extends AbstractGraphToggleAction {

  public ShowEdgeLabels() {
    super(null);
  }

  public void update(final AnActionEvent e) {
    super.update(e);
    final GraphBuilder builder = getGraphBuilder(e);

    e.getPresentation().setVisible(builder != null && builder.getGraphPresentationModel() instanceof BasicGraphPresentationModel);
  }

  protected boolean isSelected(Graph2D graph, final Project project, final AnActionEvent event) {
    final GraphBuilder builder = getGraphBuilder(event);

    if (builder != null) {
      final GraphPresentationModel graphPresentationModel = builder.getGraphPresentationModel();
      if (graphPresentationModel instanceof BasicGraphPresentationModel) {
        return ((BasicGraphPresentationModel)graphPresentationModel).isShowEdgeLabels();
      }
    }
    return false;
  }

  protected void setSelected(Graph2D graph, boolean state, final Project project, final AnActionEvent e) {
    final GraphBuilder builder = getGraphBuilder(e);

    if (builder != null) {
      final GraphPresentationModel graphPresentationModel = builder.getGraphPresentationModel();
      if (graphPresentationModel instanceof BasicGraphPresentationModel) {
        ((BasicGraphPresentationModel)graphPresentationModel).setShowEdgeLabels(state);
        builder.updateGraph();
      }
    }
  }

  protected String getText(final @NotNull Graph2D graph) {
    return ActionsBundle.message("action.Graph.show.edge.label");
  }

  @Nullable
  private static GraphBuilder getGraphBuilder(final AnActionEvent e) {
    return (GraphBuilder)e.getDataContext().getData(GraphBuilder.GRAPH_BUILDER_KEY);
  }
}
TOP

Related Classes of com.intellij.openapi.graph.builder.actions.ShowEdgeLabels

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.