Kaydet (Commit) 926744de authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Noel Grandin

merge AbstractListener into CommonListener

since CommonListener is the only subclass

Change-Id: If10ccb29991d7c48e2c20fc41330572a669f1497
Reviewed-on: https://gerrit.libreoffice.org/13094Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst b7f67f24
...@@ -75,7 +75,6 @@ $(eval $(call gb_Jar_add_sourcefiles,commonwizards,\ ...@@ -75,7 +75,6 @@ $(eval $(call gb_Jar_add_sourcefiles,commonwizards,\
wizards/com/sun/star/wizards/db/TableDescriptor \ wizards/com/sun/star/wizards/db/TableDescriptor \
wizards/com/sun/star/wizards/db/SQLQueryComposer \ wizards/com/sun/star/wizards/db/SQLQueryComposer \
wizards/com/sun/star/wizards/db/DatabaseObjectWizard \ wizards/com/sun/star/wizards/db/DatabaseObjectWizard \
wizards/com/sun/star/wizards/ui/event/AbstractListener \
wizards/com/sun/star/wizards/ui/event/CommonListener \ wizards/com/sun/star/wizards/ui/event/CommonListener \
wizards/com/sun/star/wizards/ui/event/DataAware \ wizards/com/sun/star/wizards/ui/event/DataAware \
wizards/com/sun/star/wizards/ui/event/DataAwareFields \ wizards/com/sun/star/wizards/ui/event/DataAwareFields \
......
...@@ -55,7 +55,7 @@ public class UnoDialog implements EventNames ...@@ -55,7 +55,7 @@ public class UnoDialog implements EventNames
public Resource m_oResource; public Resource m_oResource;
public XWindowPeer xWindowPeer = null; public XWindowPeer xWindowPeer = null;
private PeerConfig m_oPeerConfig; private PeerConfig m_oPeerConfig;
protected final AbstractListener guiEventListener = new CommonListener(); protected final CommonListener guiEventListener = new CommonListener();
public UnoDialog(XMultiServiceFactory xMSF) public UnoDialog(XMultiServiceFactory xMSF)
{ {
......
...@@ -25,7 +25,6 @@ import com.sun.star.wizards.common.Desktop; ...@@ -25,7 +25,6 @@ import com.sun.star.wizards.common.Desktop;
import com.sun.star.wizards.common.Helper; import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.PropertyNames; import com.sun.star.wizards.common.PropertyNames;
import com.sun.star.wizards.common.SystemDialog; import com.sun.star.wizards.common.SystemDialog;
import com.sun.star.wizards.ui.event.*;
/** /**
* This class contains convenience methods for inserting components to a dialog. * This class contains convenience methods for inserting components to a dialog.
...@@ -33,7 +32,7 @@ import com.sun.star.wizards.ui.event.*; ...@@ -33,7 +32,7 @@ import com.sun.star.wizards.ui.event.*;
* description files to a Java class which builds the same dialog through the UNO API.</p> * description files to a Java class which builds the same dialog through the UNO API.</p>
* <p>It uses an Event-Listener method, which calls a method through reflection * <p>It uses an Event-Listener method, which calls a method through reflection
* when an event on a component is triggered. * when an event on a component is triggered.
* see the classes AbstractListener, CommonListener, MethodInvocation for details.</p> * see the classes CommonListener, MethodInvocation for details.</p>
*/ */
public class UnoDialog2 extends UnoDialog public class UnoDialog2 extends UnoDialog
{ {
...@@ -50,7 +49,7 @@ public class UnoDialog2 extends UnoDialog ...@@ -50,7 +49,7 @@ public class UnoDialog2 extends UnoDialog
if (actionPerformed != null) if (actionPerformed != null)
{ {
xButton.addActionListener((XActionListener) guiEventListener); xButton.addActionListener(guiEventListener);
guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget); guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget);
} }
return xButton; return xButton;
...@@ -85,7 +84,7 @@ public class UnoDialog2 extends UnoDialog ...@@ -85,7 +84,7 @@ public class UnoDialog2 extends UnoDialog
if (itemChanged != null) if (itemChanged != null)
{ {
xCheckBox.addItemListener((XItemListener) guiEventListener); xCheckBox.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget); guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
} }
return xCheckBox; return xCheckBox;
...@@ -101,18 +100,18 @@ public class UnoDialog2 extends UnoDialog ...@@ -101,18 +100,18 @@ public class UnoDialog2 extends UnoDialog
XComboBox xComboBox = (XComboBox) insertControlModel2("com.sun.star.awt.UnoControlComboBoxModel", sName, sPropNames, oPropValues, XComboBox.class); XComboBox xComboBox = (XComboBox) insertControlModel2("com.sun.star.awt.UnoControlComboBoxModel", sName, sPropNames, oPropValues, XComboBox.class);
if (actionPerformed != null) if (actionPerformed != null)
{ {
xComboBox.addActionListener((XActionListener) guiEventListener); xComboBox.addActionListener(guiEventListener);
guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget); guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget);
} }
if (itemChanged != null) if (itemChanged != null)
{ {
xComboBox.addItemListener((XItemListener) guiEventListener); xComboBox.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget); guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
} }
if (textChanged != null) if (textChanged != null)
{ {
XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xComboBox); XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xComboBox);
xTextComponent.addTextListener((XTextListener) guiEventListener); xTextComponent.addTextListener(guiEventListener);
guiEventListener.add(sName, EVENT_TEXT_CHANGED, textChanged, eventTarget); guiEventListener.add(sName, EVENT_TEXT_CHANGED, textChanged, eventTarget);
} }
return xComboBox; return xComboBox;
...@@ -128,12 +127,12 @@ public class UnoDialog2 extends UnoDialog ...@@ -128,12 +127,12 @@ public class UnoDialog2 extends UnoDialog
XListBox xListBox = (XListBox) insertControlModel2("com.sun.star.awt.UnoControlListBoxModel", sName, sPropNames, oPropValues, XListBox.class); XListBox xListBox = (XListBox) insertControlModel2("com.sun.star.awt.UnoControlListBoxModel", sName, sPropNames, oPropValues, XListBox.class);
if (actionPerformed != null) if (actionPerformed != null)
{ {
xListBox.addActionListener((XActionListener) guiEventListener); xListBox.addActionListener(guiEventListener);
guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget); guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget);
} }
if (itemChanged != null) if (itemChanged != null)
{ {
xListBox.addItemListener((XItemListener) guiEventListener); xListBox.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget); guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
} }
return xListBox; return xListBox;
...@@ -149,7 +148,7 @@ public class UnoDialog2 extends UnoDialog ...@@ -149,7 +148,7 @@ public class UnoDialog2 extends UnoDialog
XRadioButton xRadioButton = (XRadioButton) insertControlModel2("com.sun.star.awt.UnoControlRadioButtonModel", sName, sPropNames, oPropValues, XRadioButton.class); XRadioButton xRadioButton = (XRadioButton) insertControlModel2("com.sun.star.awt.UnoControlRadioButtonModel", sName, sPropNames, oPropValues, XRadioButton.class);
if (itemChanged != null) if (itemChanged != null)
{ {
xRadioButton.addItemListener((XItemListener) guiEventListener); xRadioButton.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget); guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
} }
return xRadioButton; return xRadioButton;
...@@ -205,7 +204,7 @@ public class UnoDialog2 extends UnoDialog ...@@ -205,7 +204,7 @@ public class UnoDialog2 extends UnoDialog
XTextComponent xField = (XTextComponent) insertControlModel2(sModelClass, sName, sPropNames, oPropValues, XTextComponent.class); XTextComponent xField = (XTextComponent) insertControlModel2(sModelClass, sName, sPropNames, oPropValues, XTextComponent.class);
if (sTextChanged != null) if (sTextChanged != null)
{ {
xField.addTextListener((XTextListener) guiEventListener); xField.addTextListener(guiEventListener);
guiEventListener.add(sName, EVENT_TEXT_CHANGED, sTextChanged, eventTarget); guiEventListener.add(sName, EVENT_TEXT_CHANGED, sTextChanged, eventTarget);
} }
return UnoRuntime.queryInterface(type, xField); return UnoRuntime.queryInterface(type, xField);
......
...@@ -19,7 +19,6 @@ package com.sun.star.wizards.ui; ...@@ -19,7 +19,6 @@ package com.sun.star.wizards.ui;
import java.beans.*; import java.beans.*;
import com.sun.star.wizards.ui.event.CommonListener;
import com.sun.star.wizards.ui.event.EventNames; import com.sun.star.wizards.ui.event.EventNames;
import com.sun.star.wizards.ui.event.MethodInvocation; import com.sun.star.wizards.ui.event.MethodInvocation;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
...@@ -246,7 +245,7 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL ...@@ -246,7 +245,7 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL
guiEventListener.add("rdmNavi", EventNames.EVENT_ITEM_CHANGED, mi); guiEventListener.add("rdmNavi", EventNames.EVENT_ITEM_CHANGED, mi);
xRoadmapControl = this.xDlgContainer.getControl("rdmNavi"); xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
xRoadmapBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl); xRoadmapBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl);
xRoadmapBroadcaster.addItemListener((XItemListener) guiEventListener); xRoadmapBroadcaster.addItemListener(guiEventListener);
Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText(UIConsts.RID_COMMON + 16)); Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText(UIConsts.RID_COMMON + 16));
} }
...@@ -483,7 +482,7 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL ...@@ -483,7 +482,7 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL
// if the user used "escape" key to // if the user used "escape" key to
// close the dialog. // close the dialog.
MethodInvocation windowHidden = new MethodInvocation("windowHidden", this); MethodInvocation windowHidden = new MethodInvocation("windowHidden", this);
xWindow.addWindowListener((CommonListener) guiEventListener); xWindow.addWindowListener(guiEventListener);
String dialogName = (String) Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_NAME); String dialogName = (String) Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_NAME);
guiEventListener.add(dialogName, EVENT_ACTION_PERFORMED, windowHidden); guiEventListener.add(dialogName, EVENT_ACTION_PERFORMED, windowHidden);
......
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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 .
*/
package com.sun.star.wizards.ui.event;
import com.sun.star.awt.XControl;
import com.sun.star.lang.EventObject;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.PropertyNames;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
/**
* This class is a base class for listener classes.
* <p>It uses a hashtable to map between a ComponentName, EventName and a MethodInvokation Object.
* To use this class do the following:</p>
* <ul>
* <li>Write a subclass which implements the needed Listener(s).</li>
* <li>In the even methods, use invoke(...).</li>
* <li>When instantiating the component, register the subclass as the event listener.</li>
* <li>Write the methods which should be performed when the event occurs.</li>
* <li>call the "add" method, to define a component-event-action mapping.</li>
* </ul>
*/
public class AbstractListener
{
private final HashMap<String,MethodInvocation> mHashtable = new HashMap<String,MethodInvocation>();
public void add(String componentName, String eventName, String methodName, Object target)
{
try
{
add(componentName, eventName, new MethodInvocation(methodName, target));
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void add(String componentName, String eventName, MethodInvocation mi)
{
mHashtable.put(componentName + eventName, mi);
}
public MethodInvocation get(String componentName, String eventName)
{
return mHashtable.get(componentName + eventName);
}
public Object invoke(String componentName, String eventName, Object param)
{
try
{
MethodInvocation mi = get(componentName, eventName);
if (mi != null)
{
return mi.invoke(param);
}
else
{
return null;
}
}
catch (InvocationTargetException ite)
{
System.out.println("=======================================================");
System.out.println("=== Note: An Exception was thrown which should have ===");
System.out.println("=== caused a crash. I caught it. Please report this ===");
System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
System.out.println("=======================================================");
ite.printStackTrace();
}
catch (IllegalAccessException iae)
{
iae.printStackTrace();
}
catch (Exception ex)
{
System.out.println("=======================================================");
System.out.println("=== Note: An Exception was thrown which should have ===");
System.out.println("=== caused a crash. I caught it. Please report this ===");
System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
System.out.println("=======================================================");
ex.printStackTrace();
}
return null;
}
/**
* Rerurns the property "name" of the Object which is the source of the event.
*/
public static String getEventSourceName(EventObject eventObject)
{
XControl xControl = UnoRuntime.queryInterface(XControl.class, eventObject.Source);
return (String) Helper.getUnoPropertyValue(xControl.getModel(), PropertyNames.PROPERTY_NAME, String.class);
}
}
...@@ -17,12 +17,105 @@ ...@@ -17,12 +17,105 @@
*/ */
package com.sun.star.wizards.ui.event; package com.sun.star.wizards.ui.event;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import com.sun.star.awt.*; import com.sun.star.awt.*;
import com.sun.star.lang.EventObject; import com.sun.star.lang.EventObject;
import com.sun.star.uno.UnoRuntime;
public class CommonListener extends AbstractListener implements XActionListener, XItemListener, XTextListener, EventNames, XWindowListener, XMouseListener, XFocusListener, XKeyListener import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.PropertyNames;
/**
* <p>It uses a hashtable to map between a ComponentName, EventName and a MethodInvokation Object.
* To use this class do the following:</p>
* <ul>
* <li>Write a subclass which implements the needed Listener(s).</li>
* <li>In the even methods, use invoke(...).</li>
* <li>When instantiating the component, register the subclass as the event listener.</li>
* <li>Write the methods which should be performed when the event occurs.</li>
* <li>call the "add" method, to define a component-event-action mapping.</li>
* </ul>
*/
public class CommonListener implements XActionListener, XItemListener, XTextListener, EventNames, XWindowListener, XMouseListener, XFocusListener, XKeyListener
{ {
private final HashMap<String,MethodInvocation> mHashtable = new HashMap<String,MethodInvocation>();
public void add(String componentName, String eventName, String methodName, Object target)
{
try
{
add(componentName, eventName, new MethodInvocation(methodName, target));
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void add(String componentName, String eventName, MethodInvocation mi)
{
mHashtable.put(componentName + eventName, mi);
}
private MethodInvocation get(String componentName, String eventName)
{
return mHashtable.get(componentName + eventName);
}
private Object invoke(String componentName, String eventName, Object param)
{
try
{
MethodInvocation mi = get(componentName, eventName);
if (mi != null)
{
return mi.invoke(param);
}
else
{
return null;
}
}
catch (InvocationTargetException ite)
{
System.out.println("=======================================================");
System.out.println("=== Note: An Exception was thrown which should have ===");
System.out.println("=== caused a crash. I caught it. Please report this ===");
System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
System.out.println("=======================================================");
ite.printStackTrace();
}
catch (IllegalAccessException iae)
{
iae.printStackTrace();
}
catch (Exception ex)
{
System.out.println("=======================================================");
System.out.println("=== Note: An Exception was thrown which should have ===");
System.out.println("=== caused a crash. I caught it. Please report this ===");
System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
System.out.println("=======================================================");
ex.printStackTrace();
}
return null;
}
/**
* Returns the property "name" of the Object which is the source of the event.
*/
private static String getEventSourceName(EventObject eventObject)
{
XControl xControl = UnoRuntime.queryInterface(XControl.class, eventObject.Source);
return (String) Helper.getUnoPropertyValue(xControl.getModel(), PropertyNames.PROPERTY_NAME, String.class);
}
/** /**
* Implementation of com.sun.star.awt.XActionListener * Implementation of com.sun.star.awt.XActionListener
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment