Package org.pentaho.reporting.designer.core.actions.elements

Source Code of org.pentaho.reporting.designer.core.actions.elements.EditContentRefAction

/*
* 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) 2009 Pentaho Corporation.  All rights reserved.
*/

package org.pentaho.reporting.designer.core.actions.elements;

import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import javax.swing.Action;

import org.pentaho.reporting.designer.core.actions.AbstractElementSelectionAction;
import org.pentaho.reporting.designer.core.actions.ActionMessages;
import org.pentaho.reporting.designer.core.util.table.CustomPropertyEditorDialog;
import org.pentaho.reporting.designer.core.util.table.ResourcePropertyEditor;
import org.pentaho.reporting.engine.classic.core.AttributeNames;
import org.pentaho.reporting.engine.classic.core.Element;
import org.pentaho.reporting.engine.classic.core.metadata.AttributeMetaData;

/**
* Todo: Document me
*
* @author Thomas Morgner
*/
public class EditContentRefAction extends AbstractElementSelectionAction
{
  public EditContentRefAction()
  {
    putValue(Action.NAME, ActionMessages.getString("EditContentRefAction.Text"));
    putValue(Action.SHORT_DESCRIPTION, ActionMessages.getString("EditContentRefAction.Description"));
    putValue(Action.MNEMONIC_KEY, ActionMessages.getOptionalMnemonic("EditContentRefAction.Mnemonic"));
    putValue(Action.ACCELERATOR_KEY, ActionMessages.getOptionalKeyStroke("EditContentRefAction.Accelerator"));
  }

  protected void updateSelection()
  {
    if (isSingleElementSelection() == false)
    {
      setEnabled(false);
      return;
    }
    final Object o = getSelectionModel().getLeadSelection();
    if (o instanceof Element == false)
    {
      setEnabled(false);
      return;
    }
    final Element e = (Element) o;
    final AttributeMetaData data = e.getElementType().getMetaData().getAttributeDescription
            (AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE);
    if (data == null)
    {
      setEnabled(false);
      return;
    }
    setEnabled("Resource".equals(data.getValueRole())); // NON-NLS
  }

  public void actionPerformed(final ActionEvent e)
  {
    if (isSingleElementSelection() == false)
    {
      return;
    }
    final Object o = getSelectionModel().getLeadSelection();
    if (o instanceof Element == false)
    {
      return;
    }
    final Element element = (Element) o;
    final AttributeMetaData data = element.getElementType().getMetaData().getAttributeDescription
            (AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE);
    if (data == null)
    {
      return;
    }
    if("Resource".equals(data.getValueRole()) == false) // NON-NLS
    {
      return;
    }

    final CustomPropertyEditorDialog editorDialog;
    final Component window = getReportDesignerContext().getParent();
   
    if (window instanceof Frame)
    {
      editorDialog = new CustomPropertyEditorDialog((Frame) window);
    }
    else if (window instanceof Dialog)
    {
      editorDialog = new CustomPropertyEditorDialog((Dialog) window);
    }
    else
    {
      editorDialog = new CustomPropertyEditorDialog();
    }
    editorDialog.setTitle(ActionMessages.getString("EditContentRefAction.Text"));
    final ResourcePropertyEditor propertyEditor = new ResourcePropertyEditor(getActiveContext());
    propertyEditor.setValue
            (element.getAttribute(AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE));
    if (editorDialog.performEdit(propertyEditor))
    {
      element.setAttribute
              (AttributeNames.Core.NAMESPACE, AttributeNames.Core.VALUE, propertyEditor.getValue());
    }

  }
}
TOP

Related Classes of org.pentaho.reporting.designer.core.actions.elements.EditContentRefAction

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.