Procházet zdrojové kódy

Require implementing hasTooltip if there's custom tooltip logic (#11052)

Change-Id: I3038b97d9a7c7e144a325ce87aa849309b9b31c4
tags/7.1.0.beta1
Leif Åstrand před 11 roky
rodič
revize
453099e29f

+ 0
- 16
client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java Zobrazit soubor

writeGetters(logger, w, bundle); writeGetters(logger, w, bundle);
writeSerializers(logger, w, bundle); writeSerializers(logger, w, bundle);
writeDelegateToWidget(logger, w, bundle); writeDelegateToWidget(logger, w, bundle);
writeHasGetTooltip(logger, w, bundle);
}

/**
* @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards
* compatibility and will be removed in Vaadin 7.1
*/
@Deprecated
private void writeHasGetTooltip(TreeLogger logger, SplittingSourceWriter w,
ConnectorBundle bundle) {
Set<JClassType> types = bundle.getHasGetTooltip();
for (JClassType type : types) {
w.println("store.setHasGetTooltipInfo(%s);",
getClassLiteralString(type));
w.splitIfNeeded();
}
} }


private void writeDelegateToWidget(TreeLogger logger, private void writeDelegateToWidget(TreeLogger logger,

+ 0
- 34
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java Zobrazit soubor

private final Set<JClassType> needsGwtConstructor = new HashSet<JClassType>(); private final Set<JClassType> needsGwtConstructor = new HashSet<JClassType>();
private final Set<JClassType> visitedTypes = new HashSet<JClassType>(); private final Set<JClassType> visitedTypes = new HashSet<JClassType>();
private final Set<JClassType> needsProxySupport = new HashSet<JClassType>(); private final Set<JClassType> needsProxySupport = new HashSet<JClassType>();
private final Set<JClassType> hasGetTooltip = new HashSet<JClassType>();


private final Map<JClassType, Set<String>> identifiers = new HashMap<JClassType, Set<String>>(); private final Map<JClassType, Set<String>> identifiers = new HashMap<JClassType, Set<String>>();
private final Map<JClassType, Set<JMethod>> needsReturnType = new HashMap<JClassType, Set<JMethod>>(); private final Map<JClassType, Set<JMethod>> needsReturnType = new HashMap<JClassType, Set<JMethod>>();
return Collections.unmodifiableSet(needsDelegateToWidget); return Collections.unmodifiableSet(needsDelegateToWidget);
} }


/**
* @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards
* compatibility and will be removed in Vaadin 7.1
*/
@Deprecated
public Set<JClassType> getHasGetTooltip() {
return Collections.unmodifiableSet(hasGetTooltip);
}

/**
* @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards
* compatibility and will be removed in Vaadin 7.1
*/
@Deprecated
public void setHasGetTooltip(JClassType type) {
if (!isHasGetTooltip(type)) {
hasGetTooltip.add(type);
}
}

/**
* @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards
* compatibility and will be removed in Vaadin 7.1
*/
@Deprecated
private boolean isHasGetTooltip(JClassType type) {
if (hasGetTooltip.contains(type)) {
return true;
} else {
return previousBundle != null
&& previousBundle.isHasGetTooltip(type);
}
}
} }

+ 0
- 19
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java Zobrazit soubor

bundle.setNeedsReturnType(type, getWidget); bundle.setNeedsReturnType(type, getWidget);
} }


// Hack to detect when getTooltipInfo has a custom implementation
// #11051
JClassType getTooltipParamType = type.getOracle().findType(
"com.google.gwt.dom.client.Element");
JMethod getTooltipInfoMethod = findInheritedMethod(type,
"getTooltipInfo", getTooltipParamType);
if (getTooltipInfoMethod == null) {
logger.log(Type.ERROR, "Could not find getTooltipInfo in "
+ type.getQualifiedSourceName());
throw new UnableToCompleteException();
}
JClassType enclosingType = getTooltipInfoMethod.getEnclosingType();
if (!enclosingType.getQualifiedSourceName().equals(
AbstractComponentConnector.class.getCanonicalName())) {
logger.log(Type.WARN, type.getQualifiedSourceName()
+ " has overridden getTooltipInfo");
bundle.setHasGetTooltip(type);
}

// Check state properties for @DelegateToWidget // Check state properties for @DelegateToWidget
JMethod getState = findInheritedMethod(type, "getState"); JMethod getState = findInheritedMethod(type, "getState");
JClassType stateType = getState.getReturnType().isClass(); JClassType stateType = getState.getReturnType().isClass();

+ 19
- 0
client/src/com/vaadin/client/ComponentConnector.java Zobrazit soubor



/** /**
* Gets the tooltip info for the given element. * Gets the tooltip info for the given element.
* <p>
* When overriding this method, {@link #hasTooltip()} should also be
* overridden to return <code>true</code> in all situations where this
* method might return a non-empty result.
* </p>
* *
* @param element * @param element
* The element to lookup a tooltip for * The element to lookup a tooltip for
*/ */
public TooltipInfo getTooltipInfo(Element element); public TooltipInfo getTooltipInfo(Element element);


/**
* Check whether there might be a tooltip for this component. The framework
* will only add event listeners for automatically handling tooltips (using
* {@link #getTooltipInfo(Element)}) if this method returns true.
* <p>
* This is only done to optimize performance, so in cases where the status
* is not known, it's safer to return <code>true</code> so that there will
* be a tooltip handler even though it might not be needed in all cases.
*
* @return <code>true</code> if some part of the component might have a
* tooltip, otherwise <code>false</code>
*/
public boolean hasTooltip();

/** /**
* Called for the active (focused) connector when a situation occurs that * Called for the active (focused) connector when a situation occurs that
* the focused connector might have buffered changes which need to be * the focused connector might have buffered changes which need to be

+ 3
- 0
client/src/com/vaadin/client/VTooltip.java Zobrazit soubor

} }


if (connector != null && info != null) { if (connector != null && info != null) {
assert connector.hasTooltip() : "getTooltipInfo for "
+ Util.getConnectorString(connector)
+ " returned a tooltip even though hasTooltip claims there are no tooltips for the connector.";
currentTooltipInfo = info; currentTooltipInfo = info;
return true; return true;
} }

+ 0
- 19
client/src/com/vaadin/client/metadata/TypeDataStore.java Zobrazit soubor



private final FastStringSet delayedMethods = FastStringSet.create(); private final FastStringSet delayedMethods = FastStringSet.create();
private final FastStringSet lastOnlyMethods = FastStringSet.create(); private final FastStringSet lastOnlyMethods = FastStringSet.create();
private final FastStringSet hasGetTooltipInfo = FastStringSet.create();


private final FastStringMap<Type> returnTypes = FastStringMap.create(); private final FastStringMap<Type> returnTypes = FastStringMap.create();
private final FastStringMap<Invoker> invokers = FastStringMap.create(); private final FastStringMap<Invoker> invokers = FastStringMap.create();
public static boolean hasProperties(Type type) { public static boolean hasProperties(Type type) {
return get().properties.containsKey(type.getSignature()); return get().properties.containsKey(type.getSignature());
} }

/**
* @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards
* compatibility and will be removed in Vaadin 7.1
*/
@Deprecated
public void setHasGetTooltipInfo(Class<?> clazz) {
hasGetTooltipInfo.add(getType(clazz).getSignature());
}

/**
* @deprecated As of 7.0.1. This is just a hack to avoid breaking backwards
* compatibility and will be removed in Vaadin 7.1
*/
@Deprecated
public static boolean getHasGetTooltipInfo(Class clazz) {
return get().hasGetTooltipInfo.contains(getType(clazz).getSignature());
}
} }

+ 2
- 30
client/src/com/vaadin/client/ui/AbstractComponentConnector.java Zobrazit soubor

import com.vaadin.client.metadata.NoDataException; import com.vaadin.client.metadata.NoDataException;
import com.vaadin.client.metadata.Type; import com.vaadin.client.metadata.Type;
import com.vaadin.client.metadata.TypeData; import com.vaadin.client.metadata.TypeData;
import com.vaadin.client.metadata.TypeDataStore;
import com.vaadin.client.ui.datefield.PopupDateFieldConnector; import com.vaadin.client.ui.datefield.PopupDateFieldConnector;
import com.vaadin.client.ui.ui.UIConnector; import com.vaadin.client.ui.ui.UIConnector;
import com.vaadin.shared.AbstractComponentState; import com.vaadin.shared.AbstractComponentState;
} }
} }


/**
* {@inheritDoc}
*
* <p>
* When overriding this method, {@link #hasTooltip()} should also be
* overridden to return true in all situations where this method might
* return a non-empty result.
* </p>
*
* @see ComponentConnector#getTooltipInfo(Element)
*/
@Override @Override
public TooltipInfo getTooltipInfo(Element element) { public TooltipInfo getTooltipInfo(Element element) {
return new TooltipInfo(getState().description, getState().errorMessage); return new TooltipInfo(getState().description, getState().errorMessage);
} }


/**
* Check whether there might be a tooltip for this component. The framework
* will only add event listeners for automatically handling tooltips (using
* {@link #getTooltipInfo(Element)}) if this method returns true.
*
* @return <code>true</code> if some part of the component might have a
* tooltip, otherwise <code>false</code>
*/
private boolean hasTooltip() {
/*
* Hack to avoid breaking backwards compatibility - use a generator to
* know whether there's a custom implementation of getTooltipInfo, and
* in that case always assume that there might be tooltip.
*/
if (TypeDataStore.getHasGetTooltipInfo(getClass())) {
return true;
}

@Override
public boolean hasTooltip() {
// Normally, there is a tooltip if description or errorMessage is set // Normally, there is a tooltip if description or errorMessage is set
AbstractComponentState state = getState(); AbstractComponentState state = getState();
if (state.description != null && !state.description.equals("")) { if (state.description != null && !state.description.equals("")) {

+ 9
- 0
client/src/com/vaadin/client/ui/calendar/CalendarConnector.java Zobrazit soubor

return tooltipInfo; return tooltipInfo;
} }


@Override
public boolean hasTooltip() {
/*
* Tooltips are not processed until updateFromUIDL, so we can't be sure
* that there are no tooltips during onStateChange when this is used.
*/
return true;
}

private void updateMonthView(List<CalendarState.Day> days, private void updateMonthView(List<CalendarState.Day> days,
List<CalendarState.Event> events) { List<CalendarState.Event> events) {
CalendarState state = getState(); CalendarState state = getState();

+ 5
- 0
client/src/com/vaadin/client/ui/form/FormConnector.java Zobrazit soubor

// as a part of the actual layout // as a part of the actual layout
return null; return null;
} }

@Override
public boolean hasTooltip() {
return false;
}
} }

+ 9
- 0
client/src/com/vaadin/client/ui/formlayout/FormLayoutConnector.java Zobrazit soubor

return info; return info;
} }


@Override
public boolean hasTooltip() {
/*
* Tooltips are fetched from child connectors -> there's no quick way of
* checking whether there might a tooltip hiding somewhere
*/
return true;
}

} }

+ 10
- 0
client/src/com/vaadin/client/ui/menubar/MenuBarConnector.java Zobrazit soubor



return info; return info;
} }

@Override
public boolean hasTooltip() {
/*
* Item tooltips are not processed until updateFromUIDL, so we can't be
* sure that there are no tooltips during onStateChange when this method
* is used.
*/
return true;
}
} }

+ 10
- 0
client/src/com/vaadin/client/ui/table/TableConnector.java Zobrazit soubor

return info; return info;
} }


@Override
public boolean hasTooltip() {
/*
* Tooltips for individual rows and cells are not processed until
* updateFromUIDL, so we can't be sure that there are no tooltips during
* onStateChange when this method is used.
*/
return true;
}

@Override @Override
public void onConnectorHierarchyChange( public void onConnectorHierarchyChange(
ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

+ 10
- 0
client/src/com/vaadin/client/ui/tabsheet/TabsheetConnector.java Zobrazit soubor

return info; return info;
} }


@Override
public boolean hasTooltip() {
/*
* Tab tooltips are not processed until updateFromUIDL, so we can't be
* sure that there are no tooltips during onStateChange when this method
* is used.
*/
return true;
}

@Override @Override
public void onConnectorHierarchyChange( public void onConnectorHierarchyChange(
ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {

+ 10
- 0
client/src/com/vaadin/client/ui/tree/TreeConnector.java Zobrazit soubor

return info; return info;
} }


@Override
public boolean hasTooltip() {
/*
* Item tooltips are not processed until updateFromUIDL, so we can't be
* sure that there are no tooltips during onStateChange when this method
* is used.
*/
return true;
}

} }

+ 5
- 6
client/src/com/vaadin/client/ui/ui/UIConnector.java Zobrazit soubor

import com.vaadin.client.ConnectorMap; import com.vaadin.client.ConnectorMap;
import com.vaadin.client.Focusable; import com.vaadin.client.Focusable;
import com.vaadin.client.Paintable; import com.vaadin.client.Paintable;
import com.vaadin.client.TooltipInfo;
import com.vaadin.client.UIDL; import com.vaadin.client.UIDL;
import com.vaadin.client.VConsole; import com.vaadin.client.VConsole;
import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent;
} }


@Override @Override
public TooltipInfo getTooltipInfo(com.google.gwt.dom.client.Element element) {
public boolean hasTooltip() {
/* /*
* Override method to make AbstractComponentConnector.hasTooltip()
* return true so there's a top level handler that takes care of hiding
* tooltips whenever the mouse is moved somewhere else.
* Always return true so there's always top level tooltip handler that
* takes care of hiding tooltips whenever the mouse is moved somewhere
* else.
*/ */
return super.getTooltipInfo(element);
return true;
} }


/** /**

Načítá se…
Zrušit
Uložit