forked from amazingfate/loongoffice
2009-06-30 08:58:13 +0200 fs r273488 : merging latest changes from CWS dba32c 2009-06-29 11:40:42 +0200 oj r273459 : #i101652# fix token handling 2009-06-26 09:27:30 +0200 oj r273394 : #i101994# wrong condition checked 2009-06-22 12:09:04 +0200 fs r273210 : merging latest changes from CWS dba32c 2009-06-18 11:01:06 +0200 fs r273108 : merge latest changes from CWS dba32c 2009-06-17 14:19:33 +0200 oj r273072 : handle images at the correct position 2009-06-17 13:37:19 +0200 oj r273067 : compile error 2009-06-17 13:35:58 +0200 oj r273066 : #i102201# handle images 2009-06-17 13:27:21 +0200 oj r273065 : #i80917# disable checkbox for internal copy 2009-06-17 13:25:38 +0200 oj r273064 : #i80917# disable checkbox for internal copy 2009-06-15 12:59:16 +0200 fs r272978 : merging latest changes from CWS dba32c 2009-06-15 10:45:58 +0200 fs r272967 : CWS-TOOLING: rebase CWS dba32d to trunk@272827 (milestone: DEV300:m50) 2009-06-15 08:41:05 +0200 fs r272960 : merging changes from CWS dba32c (resulting from rebasing dba32c to m50) 2009-06-03 12:22:32 +0200 fs r272554 : merging latest changes from CWS dba32c 2009-06-03 11:11:27 +0200 fs r272549 : #i100818# special treatment for DataAwareness not needed anymore 2009-06-03 11:07:01 +0200 fs r272548 : #i10000# removed package declaration 2009-06-03 09:21:03 +0200 oj r272537 : #i93465# save window states 2009-06-03 08:56:25 +0200 oj r272535 : solve compiler warnings 2009-06-03 08:55:02 +0200 oj r272534 : #i102295# export shapes i the first cell 2009-06-03 07:35:18 +0200 oj r272533 : #i101994# check for - and + prefix 2009-06-03 06:51:38 +0200 oj r272531 : #i101463# use uncomposed table name 2009-06-03 06:33:06 +0200 oj r272530 : #i102019# word corrected 2009-06-02 14:58:28 +0200 fs r272507 : #i102443# call initializeParser from LoadFinished 2009-06-02 14:30:10 +0200 oj r272504 : #i102019# introduce static ints 2009-06-02 13:51:02 +0200 oj r272501 : #i102439# wrong method used 2009-06-02 13:44:09 +0200 fs r272500 : #i102440# when tampering with Order/GroupBy, reset the cached columns 2009-06-02 10:53:01 +0200 fs r272487 : #i102234# preserve the original filter when using a 0=1 filter 2009-06-02 10:21:21 +0200 oj r272486 : #i100535# handle time values as float 2009-06-02 10:19:07 +0200 fs r272485 : merging latest changes from CWS dba32c 2009-05-29 16:00:15 +0200 fs r272467 : merging latest changes from dba32c 2009-05-29 15:31:25 +0200 fs r272462 : merging latest changes from dba32c 2009-05-29 10:58:03 +0200 oj r272438 : #101135# export embedded-text 2009-05-29 08:17:57 +0200 oj r272431 : #i80917# make attribute not optional 2009-05-29 08:17:32 +0200 oj r272430 : remoe unused token 2009-05-29 07:17:15 +0200 oj r272429 : #i80917# make attribute not optional 2009-05-28 12:48:14 +0200 oj r272401 : #i102201# insert images in context menu 2009-05-28 12:47:44 +0200 oj r272400 : #i80917# add new attribute to handle first line 2009-05-28 12:16:12 +0200 oj r272397 : #i96134# add / to path when it doesn't exist 2009-05-28 12:11:08 +0200 oj r272390 : #i80917# add new attribute to handle first line 2009-05-28 11:33:35 +0200 oj r272388 : #i101652# add new checkbox to handle header line as column names 2009-05-28 11:30:15 +0200 oj r272387 : #i101652# add localize 2009-05-28 11:15:53 +0200 oj r272386 : merge from dba32c 2009-05-28 09:08:25 +0200 fs r272378 : merged a build fix from CWS dba32c
232 lines
8.4 KiB
Java
232 lines
8.4 KiB
Java
/*************************************************************************
|
|
*
|
|
* $RCSfile: ButtonOperator.java,v $
|
|
*
|
|
* $Revision: 1.4 $
|
|
*
|
|
* last change: $Author: rt $ $Date: 2005-01-31 16:27:59 $
|
|
*
|
|
* The Contents of this file are made available subject to the terms of
|
|
* the BSD license.
|
|
*
|
|
* Copyright (c) 2003 by Sun Microsystems, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. Neither the name of Sun Microsystems, Inc. nor the names of its
|
|
* contributors may be used to endorse or promote products derived
|
|
* from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
*************************************************************************/
|
|
package org.openoffice.sdk.forms;
|
|
|
|
// java base stuff
|
|
import com.sun.star.awt.ActionEvent;
|
|
import com.sun.star.awt.XActionListener;
|
|
import com.sun.star.awt.XButton;
|
|
import com.sun.star.beans.XPropertySet;
|
|
import com.sun.star.form.runtime.FormOperations;
|
|
import com.sun.star.form.runtime.XFeatureInvalidation;
|
|
import com.sun.star.form.runtime.XFormOperations;
|
|
import com.sun.star.lang.EventObject;
|
|
import com.sun.star.uno.UnoRuntime;
|
|
import com.sun.star.uno.XComponentContext;
|
|
import java.util.Vector;
|
|
|
|
|
|
/**************************************************************************/
|
|
/** a helper class for operating the buttons
|
|
*/
|
|
public class ButtonOperator implements XActionListener, XFeatureInvalidation
|
|
{
|
|
private XComponentContext m_componentContext;
|
|
private DocumentHelper m_aDocument;
|
|
private XPropertySet m_form;
|
|
private XFormOperations m_formOperations;
|
|
|
|
private Vector m_aButtons;
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** ctor
|
|
*/
|
|
public ButtonOperator( XComponentContext xCtx, DocumentHelper aDocument, XPropertySet _form )
|
|
{
|
|
m_componentContext = xCtx;
|
|
m_aDocument = aDocument;
|
|
m_form = _form;
|
|
m_aButtons = new Vector();
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
private short getAssociatedFormFeature( XPropertySet _buttonModel )
|
|
{
|
|
short formFeature = -1;
|
|
try
|
|
{
|
|
formFeature = Short.valueOf( (String)_buttonModel.getPropertyValue( "Tag" ) );
|
|
}
|
|
catch( com.sun.star.uno.Exception e )
|
|
{
|
|
}
|
|
return formFeature;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** get's the button which we operate and which is responsible for a given URL
|
|
*/
|
|
private XPropertySet getButton( short _formFeature )
|
|
{
|
|
for ( int i=0; i < m_aButtons.size(); ++i )
|
|
{
|
|
XPropertySet button = (XPropertySet)m_aButtons.elementAt( i );
|
|
if ( _formFeature == getAssociatedFormFeature( button ) )
|
|
return button;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** announces a button which the operator should be responsible for
|
|
*/
|
|
private int getButtonIndex( XPropertySet xButton )
|
|
{
|
|
int nPos = -1;
|
|
for ( int i=0; ( i < m_aButtons.size() ) && ( -1 == nPos ); ++i )
|
|
{
|
|
if ( xButton.equals( m_aButtons.elementAt( i ) ) )
|
|
nPos = i;
|
|
}
|
|
return nPos;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/** announces a button which the operator should be responsible for
|
|
*/
|
|
public void addButton( XPropertySet _buttonModel, short _formFeature ) throws java.lang.Exception
|
|
{
|
|
// the current view to the document
|
|
DocumentViewHelper aCurrentView = m_aDocument.getCurrentView();
|
|
|
|
// add a listener so we get noticed if the user presses the button
|
|
XButton xButtonControl = (XButton)UnoRuntime.queryInterface( XButton.class,
|
|
aCurrentView.getFormControl( _buttonModel ) );
|
|
xButtonControl.addActionListener( this );
|
|
|
|
_buttonModel.setPropertyValue( "Tag", String.valueOf( _formFeature ) );
|
|
|
|
// remember the button
|
|
m_aButtons.add( _buttonModel );
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
public void revokeButton( XPropertySet xButtonModel )
|
|
{
|
|
int nPos = getButtonIndex( xButtonModel );
|
|
if ( -1 < nPos )
|
|
{
|
|
m_aButtons.remove( nPos );
|
|
}
|
|
}
|
|
|
|
/* ==================================================================
|
|
= XActionListener
|
|
================================================================== */
|
|
/* ------------------------------------------------------------------ */
|
|
/* called when a button has been pressed
|
|
*/
|
|
public void actionPerformed( ActionEvent aEvent ) throws com.sun.star.uno.RuntimeException
|
|
{
|
|
// get the model's name
|
|
XPropertySet buttonModel = (XPropertySet)FLTools.getModel( aEvent.Source, XPropertySet.class );
|
|
try
|
|
{
|
|
short formFeature = getAssociatedFormFeature( buttonModel );
|
|
if ( formFeature != -1 )
|
|
m_formOperations.execute( formFeature );
|
|
}
|
|
catch( final com.sun.star.uno.Exception e )
|
|
{
|
|
}
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* (to be) called when the form layer has been switched to alive mode
|
|
* @todo
|
|
* register as listener somewhere ...
|
|
*/
|
|
public void onFormsAlive()
|
|
{
|
|
try
|
|
{
|
|
m_formOperations = FormOperations.createWithFormController(
|
|
m_componentContext, m_aDocument.getCurrentView().getFormController( m_form ) );
|
|
m_formOperations.setFeatureInvalidation( this );
|
|
invalidateAllFeatures();
|
|
}
|
|
catch( final com.sun.star.uno.Exception e )
|
|
{
|
|
}
|
|
}
|
|
|
|
/* ==================================================================
|
|
= XEventListener
|
|
================================================================== */
|
|
public void disposing( EventObject aEvent )
|
|
{
|
|
// not interested in
|
|
}
|
|
|
|
/* ==================================================================
|
|
= XFeatureInvalidation
|
|
================================================================== */
|
|
private void updateButtonState( XPropertySet _buttonModel, short _formFeature )
|
|
{
|
|
try
|
|
{
|
|
_buttonModel.setPropertyValue( "Enabled", m_formOperations.isEnabled( _formFeature ) );
|
|
}
|
|
catch( com.sun.star.uno.Exception e )
|
|
{
|
|
}
|
|
}
|
|
|
|
public void invalidateFeatures( short[] _features ) throws com.sun.star.uno.RuntimeException
|
|
{
|
|
for ( int i=0; i<_features.length; ++i )
|
|
{
|
|
XPropertySet buttonModel = getButton( _features[i] );
|
|
if ( buttonModel != null )
|
|
updateButtonState( buttonModel, _features[i] );
|
|
}
|
|
}
|
|
|
|
public void invalidateAllFeatures() throws com.sun.star.uno.RuntimeException
|
|
{
|
|
for ( int i=0; i < m_aButtons.size(); ++i )
|
|
{
|
|
XPropertySet buttonModel = (XPropertySet)m_aButtons.elementAt( i );
|
|
updateButtonState( buttonModel, getAssociatedFormFeature( buttonModel ) );
|
|
}
|
|
}
|
|
};
|
|
|