Pārlūkot izejas kodu

#1394 enable implementing Focusable components outside the com.vaadin.ui package

svn changeset:12274/svn branch:6.3
tags/6.7.0.beta1
Henri Sara pirms 14 gadiem
vecāks
revīzija
8d89a2f253

+ 23
- 0
src/com/vaadin/ui/AbstractComponent.java Parādīt failu

@@ -116,6 +116,11 @@ public abstract class AbstractComponent implements Component, MethodEventSource
*/
private Locale locale;

/**
* The component should receive focus (if {@link Focusable}) when attached.
*/
private boolean delayedFocus;

/**
* List of repaint request listeners or null if not listened at all.
*/
@@ -628,6 +633,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource
*/
public void attach() {
requestRepaint();
if (delayedFocus) {
focus();
}
}

/*
@@ -637,6 +645,21 @@ public abstract class AbstractComponent implements Component, MethodEventSource
public void detach() {
}

/**
* Sets the focus for this component if the component is {@link Focusable}.
*/
protected void focus() {
if (this instanceof Focusable) {
final Application app = getApplication();
if (app != null) {
getWindow().setFocusedComponent((Focusable) this);
delayedFocus = false;
} else {
delayedFocus = true;
}
}
}

/*
* Gets the parent application of the component. Don't add a JavaDoc comment
* here, we use the default documentation from implemented interface.

+ 4
- 17
src/com/vaadin/ui/AbstractField.java Parādīt failu

@@ -13,7 +13,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;

import com.vaadin.Application;
import com.vaadin.data.Buffered;
import com.vaadin.data.Property;
import com.vaadin.data.Validatable;
@@ -59,8 +58,6 @@ public abstract class AbstractField extends AbstractComponent implements Field,

/* Private members */

private boolean delayedFocus;

/**
* Value of the abstract field.
*/
@@ -978,19 +975,12 @@ public abstract class AbstractField extends AbstractComponent implements Field,

}

/*
* (non-Javadoc)
*
* @see com.vaadin.ui.Component.Focusable#focus()
/**
* {@inheritDoc}
*/
@Override
public void focus() {
final Application app = getApplication();
if (app != null) {
getWindow().setFocusedComponent(this);
delayedFocus = false;
} else {
delayedFocus = true;
}
super.focus();
}

/**
@@ -1069,9 +1059,6 @@ public abstract class AbstractField extends AbstractComponent implements Field,
@Override
public void attach() {
super.attach();
if (delayedFocus) {
focus();
}
if (actionManager != null) {
actionManager.setViewer(getWindow());
}

+ 4
- 26
src/com/vaadin/ui/Upload.java Parādīt failu

@@ -63,8 +63,6 @@ import com.vaadin.terminal.gwt.client.ui.VUpload;
@ClientWidget(VUpload.class)
public class Upload extends AbstractComponent implements Component.Focusable {

private boolean delayedFocus;

/**
* Upload buffer size.
*/
@@ -859,19 +857,12 @@ public class Upload extends AbstractComponent implements Component.Focusable {
this.receiver = receiver;
}

/*
* (non-Javadoc)
*
* @see com.vaadin.ui.Component.Focusable#focus()
/**
* {@inheritDoc}
*/
@Override
public void focus() {
final Application app = getApplication();
if (app != null) {
getWindow().setFocusedComponent(this);
delayedFocus = false;
} else {
delayedFocus = true;
}
super.focus();
}

/**
@@ -1024,17 +1015,4 @@ public class Upload extends AbstractComponent implements Component.Focusable {
this.buttonCaption = buttonCaption;
}

/**
* Notifies the component that it is connected to an application.
*
* @see com.vaadin.ui.Component#attach()
*/
@Override
public void attach() {
super.attach();
if (delayedFocus) {
focus();
}
}

}

Notiek ielāde…
Atcelt
Saglabāt