diff options
author | Carsten Drossel | 2009-03-13 11:35:18 -0400 |
---|---|---|
committer | Carsten Drossel | 2009-03-13 11:35:18 -0400 |
commit | 5faecc33b73689943efe238549eb629229fe51cb (patch) | |
tree | d7bd463bd37ffb124f20988c19f6a8b68a342f51 | |
parent | c110d94357b14c7d3ce5ae9f8a1d29236c704b15 (diff) | |
download | org.eclipse.riena-5faecc33b73689943efe238549eb629229fe51cb.zip org.eclipse.riena-5faecc33b73689943efe238549eb629229fe51cb.tar.gz org.eclipse.riena-5faecc33b73689943efe238549eb629229fe51cb.tar.xz |
extracted superclass AbstractActionRidget to allow custom ActionRidgets
3 files changed, 151 insertions, 108 deletions
diff --git a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionObserver.java b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionObserver.java index 97e2d04..703fb32 100644 --- a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionObserver.java +++ b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionObserver.java @@ -11,20 +11,21 @@ package org.eclipse.riena.internal.ui.ridgets.swt; import org.eclipse.core.runtime.Assert; -import org.eclipse.riena.core.util.ListenerList; -import org.eclipse.riena.ui.ridgets.IActionListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.riena.core.util.ListenerList; +import org.eclipse.riena.ui.ridgets.IActionListener; + /** * This class notifies a collection of action {@link IActionListener} when a * widget is selected. */ -class ActionObserver extends SelectionAdapter { +public class ActionObserver extends SelectionAdapter { private ListenerList<IActionListener> actionListeners; - ActionObserver() { + public ActionObserver() { super(); } @@ -42,7 +43,7 @@ class ActionObserver extends SelectionAdapter { * @throws RuntimeException * if IActionListener is null */ - void addListener(IActionListener listener) { + public void addListener(IActionListener listener) { Assert.isNotNull(listener, "listener is null"); //$NON-NLS-1$ if (actionListeners == null) { actionListeners = new ListenerList<IActionListener>(IActionListener.class); @@ -50,7 +51,7 @@ class ActionObserver extends SelectionAdapter { actionListeners.add(listener); } - void removeListener(IActionListener listener) { + public void removeListener(IActionListener listener) { if (actionListeners != null) { actionListeners.remove(listener); } diff --git a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionRidget.java b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionRidget.java index 2f15ac6..e9db320 100644 --- a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionRidget.java +++ b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/ActionRidget.java @@ -10,28 +10,30 @@ *******************************************************************************/ package org.eclipse.riena.internal.ui.ridgets.swt; -import java.beans.EventHandler; - -import org.eclipse.riena.ui.ridgets.IActionListener; -import org.eclipse.riena.ui.ridgets.IActionRidget; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Button; -public class ActionRidget extends AbstractSWTRidget implements IActionRidget { +import org.eclipse.riena.ui.ridgets.swt.AbstractActionRidget; - private static final String EMPTY_STRING = ""; //$NON-NLS-1$ +public class ActionRidget extends AbstractActionRidget { private Button button; - private String text; - private String icon; - private ActionObserver actionObserver; - private boolean textAlreadyInitialized; - private boolean useRidgetIcon; - public ActionRidget() { - actionObserver = new ActionObserver(); - textAlreadyInitialized = false; - useRidgetIcon = false; + @Override + public Button getUIControl() { + return (Button) super.getUIControl(); + } + + protected String getUIControlText() { + return getUIControl().getText(); + } + + protected void setUIControlText(String text) { + getUIControl().setText(text); + } + + protected void setUIControlImage(Image image) { + getUIControl().setImage(image); } @Override @@ -51,22 +53,6 @@ public class ActionRidget extends AbstractSWTRidget implements IActionRidget { } } - /** - * If the text of the ridget has no value, initialize it with the text of - * the UI control. - */ - private void initText() { - if ((text == null) && (!textAlreadyInitialized)) { - if ((getUIControl()) != null && !(getUIControl().isDisposed())) { - text = getUIControl().getText(); - if (text == null) { - text = EMPTY_STRING; - } - textAlreadyInitialized = true; - } - } - } - @Override protected void unbindUIControl() { if (button != null) { @@ -75,75 +61,4 @@ public class ActionRidget extends AbstractSWTRidget implements IActionRidget { } } - @Override - public Button getUIControl() { - return (Button) super.getUIControl(); - } - - public final void addListener(IActionListener listener) { - actionObserver.addListener(listener); - } - - public final void addListener(Object target, String action) { - addListener(EventHandler.create(IActionListener.class, target, action)); - } - - public final void removeListener(IActionListener listener) { - actionObserver.removeListener(listener); - } - - /** - * Always returns true because mandatory markers do not make sense for this - * ridget. - */ - @Override - public boolean isDisableMandatoryMarker() { - return true; - } - - public String getIcon() { - return icon; - } - - public final String getText() { - return text; - } - - public void setIcon(String icon) { - boolean oldUseRidgetIcon = useRidgetIcon; - useRidgetIcon = true; - String oldIcon = this.icon; - this.icon = icon; - if (hasChanged(oldIcon, icon) || !oldUseRidgetIcon) { - updateUIIcon(); - } - } - - public final void setText(String newText) { - this.text = newText; - updateUIText(); - } - - // helping methods - // //////////////// - - private void updateUIText() { - if (button != null) { - button.setText(text); - } - } - - private void updateUIIcon() { - Button control = getUIControl(); - if (control != null) { - Image image = null; - if (icon != null) { - image = getManagedImage(icon); - } - if ((image != null) || useRidgetIcon) { - control.setImage(image); - } - } - } - } diff --git a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractActionRidget.java b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractActionRidget.java new file mode 100644 index 0000000..d0c19ea --- /dev/null +++ b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/ui/ridgets/swt/AbstractActionRidget.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2007, 2009 compeople AG and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * compeople AG - initial API and implementation + *******************************************************************************/ +package org.eclipse.riena.ui.ridgets.swt; + +import java.beans.EventHandler; + +import org.eclipse.swt.graphics.Image; + +import org.eclipse.riena.internal.ui.ridgets.swt.AbstractSWTRidget; +import org.eclipse.riena.internal.ui.ridgets.swt.ActionObserver; +import org.eclipse.riena.ui.ridgets.IActionListener; +import org.eclipse.riena.ui.ridgets.IActionRidget; + +/** + * + */ +public abstract class AbstractActionRidget extends AbstractSWTRidget implements IActionRidget { + private static final String EMPTY_STRING = ""; //$NON-NLS-1$ + + private String text; + private String icon; + protected ActionObserver actionObserver; + private boolean textAlreadyInitialized; + private boolean useRidgetIcon; + + public AbstractActionRidget() { + actionObserver = new ActionObserver(); + textAlreadyInitialized = false; + useRidgetIcon = false; + } + + /** + * If the text of the ridget has no value, initialize it with the text of + * the UI control. + */ + protected void initText() { + if ((text == null) && (!textAlreadyInitialized)) { + if ((getUIControl()) != null && !(getUIControl().isDisposed())) { + text = getUIControlText(); + if (text == null) { + text = EMPTY_STRING; + } + textAlreadyInitialized = true; + } + } + } + + protected abstract String getUIControlText(); + + public final void addListener(IActionListener listener) { + actionObserver.addListener(listener); + } + + public final void addListener(Object target, String action) { + addListener(EventHandler.create(IActionListener.class, target, action)); + } + + public final void removeListener(IActionListener listener) { + actionObserver.removeListener(listener); + } + + /** + * Always returns true because mandatory markers do not make sense for this + * ridget. + */ + @Override + public boolean isDisableMandatoryMarker() { + return true; + } + + public String getIcon() { + return icon; + } + + public final String getText() { + return text; + } + + public void setIcon(String icon) { + boolean oldUseRidgetIcon = useRidgetIcon; + useRidgetIcon = true; + String oldIcon = this.icon; + this.icon = icon; + if (hasChanged(oldIcon, icon) || !oldUseRidgetIcon) { + updateUIIcon(); + } + } + + public final void setText(String newText) { + this.text = newText; + updateUIText(); + } + + // helping methods + // //////////////// + + protected void updateUIText() { + if (getUIControl() != null) { + setUIControlText(getText()); + } + } + + protected abstract void setUIControlText(String text); + + protected void updateUIIcon() { + if (getUIControl() != null) { + Image image = null; + if (icon != null) { + image = getManagedImage(icon); + } + if ((image != null) || useRidgetIcon) { + setUIControlImage(image); + } + } + } + + protected abstract void setUIControlImage(Image image); + +} |