<commit_before>/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * Copyright (c) 2008 - 2009 Pentaho Corporation, .  All rights reserved.
 */

package org.pentaho.reporting.designer.core.editor.structuretree;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.TransferHandler;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;

import org.pentaho.reporting.designer.core.ReportDesignerContext;
import org.pentaho.reporting.designer.core.actions.global.CopyAction;
import org.pentaho.reporting.designer.core.actions.global.CutAction;
import org.pentaho.reporting.designer.core.actions.global.PasteAction;
import org.pentaho.reporting.designer.core.actions.report.EditParametersAction;
import org.pentaho.reporting.designer.core.actions.report.EditQueryAction;
import org.pentaho.reporting.designer.core.editor.ContextMenuUtility;
import org.pentaho.reporting.designer.core.editor.ReportRenderContext;
import org.pentaho.reporting.designer.core.model.selection.ReportSelectionModel;
import org.pentaho.reporting.designer.core.util.SidePanel;
import org.pentaho.reporting.designer.core.util.exceptions.UncaughtExceptionsModel;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.ParameterMapping;
import org.pentaho.reporting.engine.classic.core.ReportDataFactoryException;
import org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry;

/**
 * By listening for update events, we could keep track of the trees and use a separate JTree for each report which
 * enables us to preserve the tree state on context switches.
 *
 * @author <NAME>
 */
public class StructureTreePanel extends SidePanel
{
  private class TreeLeadSelectionListener implements TreeSelectionListener
  {
    /**
     * Called whenever the value of the selection changes.
     *
     * @param e the event that characterizes the change.
     */
    public void valueChanged(final TreeSelectionEvent e)
    {
      final JTree tree = getTree();
      final TreePath selectionPath = tree.getLeadSelectionPath();
      if (selectionPath == null)
      {
        setLeadSelection(null);
        return;
      }

      setLeadSelection(selectionPath.getLastPathComponent());
    }
  }


  private class ReportTreeContextMenuHandler extends MouseAdapter
  {
    private ReportTreeContextMenuHandler()
    {
    }


    private void createPopupMenu(final MouseEvent e)
    {
      final JTree tree = getTree();
      final ReportDesignerContext context = getReportDesignerContext();
      if (context.getActiveContext() == null)
      {
        return;
      }

      final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
      if (path == null)
      {
        return;
      }
      if (tree.getSelectionModel().isPathSelected(path) == false)
      {
        tree.getSelectionModel().addSelectionPath(path);
      }

      final Object o = path.getLastPathComponent();
      final JPopupMenu pop = ContextMenuUtility.getMenu(context, o);
      if (pop == null)
      {
        return;
      }
      pop.show(tree, e.getX(), e.getY());
    }

    public void mouseClicked(final MouseEvent e)
    {
      if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
      {
        final JTree tree = getTree();
        final TreePath selectionPath = tree.getLeadSelectionPath();
        if (selectionPath == null)
        {
          return;
        }
        final Object selection = selectionPath.getLastPathComponent();
        try
        {
          if (selection instanceof ParameterDefinitionEntry)
          {
            final ParameterDefinitionEntry parameterDefinitionEntry = (ParameterDefinitionEntry) selection;
            EditParametersAction.performEditMasterReportParameters(getReportDesignerContext(), parameterDefinitionEntry);
          }
          else if (selection instanceof ParameterMapping)<commit_msg>PRD-4249: handle multi-select of datasource<commit_after>/*
 * This program is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
 * Foundation.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this
 * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
 * or from the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * This program 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 Lesser General Public License for more details.
 *
 * Copyright (c) 2008 - 2009 Pentaho Corporation, .  All rights reserved.
 */

package org.pentaho.reporting.designer.core.editor.structuretree;

import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Action;
import javax.swing.ActionMap;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.TransferHandler;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;

import org.pentaho.reporting.designer.core.ReportDesignerContext;
import org.pentaho.reporting.designer.core.actions.global.CopyAction;
import org.pentaho.reporting.designer.core.actions.global.CutAction;
import org.pentaho.reporting.designer.core.actions.global.PasteAction;
import org.pentaho.reporting.designer.core.actions.report.EditParametersAction;
import org.pentaho.reporting.designer.core.actions.report.EditQueryAction;
import org.pentaho.reporting.designer.core.editor.ContextMenuUtility;
import org.pentaho.reporting.designer.core.editor.ReportRenderContext;
import org.pentaho.reporting.designer.core.model.selection.ReportSelectionModel;
import org.pentaho.reporting.designer.core.util.SidePanel;
import org.pentaho.reporting.designer.core.util.exceptions.UncaughtExceptionsModel;
import org.pentaho.reporting.engine.classic.core.DataFactory;
import org.pentaho.reporting.engine.classic.core.ParameterMapping;
import org.pentaho.reporting.engine.classic.core.ReportDataFactoryException;
import org.pentaho.reporting.engine.classic.core.parameters.ParameterDefinitionEntry;

/**
 * By listening for update events, we could keep track of the trees and use a separate JTree for each report which
 * enables us to preserve the tree state on context switches.
 *
 * @author <NAME>
 */
public class StructureTreePanel extends SidePanel
{
  private class TreeLeadSelectionListener implements TreeSelectionListener
  {
    /**
     * Called whenever the value of the selection changes.
     *
     * @param e the event that characterizes the change.
     */
    public void valueChanged(final TreeSelectionEvent e)
    {
      final JTree tree = getTree();
      final TreePath selectionPath = tree.getLeadSelectionPath();
      if (selectionPath == null)
      {
        setLeadSelection(null);
        return;
      }

      setLeadSelection(selectionPath.getLastPathComponent());
    }
  }


  private class ReportTreeContextMenuHandler extends MouseAdapter
  {
    private ReportTreeContextMenuHandler()
    {
    }


    private void createPopupMenu(final MouseEvent e)
    {
      final JTree tree = getTree();
      final ReportDesignerContext context = getReportDesignerContext();
      if (context.getActiveContext() == null)
      {
        return;
      }

      final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
      if (path == null)
      {
        return;
      }
      if (tree.getSelectionModel().isPathSelected(path) == false)
      {
        tree.getSelectionModel().setSelectionPath(path);
      }

      final Object o = path.getLastPathComponent();
      final JPopupMenu pop = ContextMenuUtility.getMenu(context, o);
      if (pop == null)
      {
        return;
      }
      pop.show(tree, e.getX(), e.getY());
    }

    public void mouseClicked(final MouseEvent e)
    {
      if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
      {
        final JTree tree = getTree();
        final TreePath selectionPath = tree.getLeadSelectionPath();
        if (selectionPath == null)
        {
          return;
        }
        final Object selection = selectionPath.getLastPathComponent();
        try
        {
          if (selection instanceof ParameterDefinitionEntry)
          {
            final ParameterDefinitionEntry parameterDefinitionEntry = (ParameterDefinitionEntry) selection;
            EditParametersAction.performEditMasterReportParameters(getReportDesignerContext(), parameterDefinitionEntry);
          }
          else if (selection instanceof ParameterMapping)
{'fraction_non_alphanumeric': 0.08752802119421235, 'fraction_numerical': 0.0055023435907886695, 'mean_word_length': 3.6015002344116267, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3962724', 'n_tokens_mistral': 2686, 'n_tokens_neox': 2599, 'n_words': 707}