I am new to the forum and to programming so hopefully I give you enough details and precise information needed to understand my question.
I am working with vaadin 7 in java EE web aplication and I have a layout problem/phanomena that I cannot explain and I could not find a solution on the net. Basically, when I start the server and test my application on localhost everything looks right. When I open a dialogue window and close it again, the layout of the site looks displaced. I could not find a pattern as to which click causes this effect. Sometimes it happens also when I only change a view. This is how it should look like and this is how it does look like after working in the application.
I looked through the devloper tool in the browser and noticed that in the working html, the attributes "top" and "left" are set for the gridlayout-slot. In the displaced layout these attributes are not set. Furthermore, it seems that the problem occurs more often in chrome. It does also happen in firefox but less often.
I use VerticalLayout, GridLayout and FormLayout.
Did you have similar experience? I am wondering how and when the html files are generated from the vaadin code to find out why they change and how I can fix it.
I am not sure which code exactly is causing the problem, so I am not sure what to post. If you have an idea where to look, I can add more code. Here is how the Dialog is set up:
public class Dialog extends Window implements ClickListener
public Dialog(CustomController controller, String title)
{
super(title);
setModal(true);
setStyleName("dialogWindow");
this.controller = controller;
setWidth("65.0%");
setHeight("90.0%");
// top level component properties
panLayout = new GridLayout();
panLayout.setWidth("100%");
panLayout.setHeight("100%");
buildPanToolbar();
panLayout.addComponent(panToolbar);
buildPanTop();
panLayout.addComponent(panTop);
buildPanTabs();
panLayout.addComponent(tabsheet);
panLayout.setComponentAlignment(tabsheet, Alignment.MIDDLE_CENTER);
panLayout.setRowExpandRatio(2, 1.0f);
tfThema.focus();
setContent(panLayout);
}
The buildSomething() functions are all a combination of GridLayout, FormLayout, HorizontalLayout and VerticalLayout. Below is the buildPanToolbar() function as an example
private void buildPanToolbar()
{
panToolbar = new HorizontalLayout();
panToolbar.setImmediate(false);
panToolbar.setWidth("100%");
panToolbar.setHeight("25px");
panToolbar.setMargin(false);
panToolbar.setSpacing(true);
panToolbar.setStyleName("toolbar");
HorizontalLayout panHelpToolbar = new HorizontalLayout();
panHelpToolbar.setImmediate(false);
panHelpToolbar.setWidth("-1px");
panHelpToolbar.setHeight("25px");
panHelpToolbar.setMargin(false);
panHelpToolbar.setSpacing(true);
panHelpToolbar.setStyleName("toolbarButtons");
panToolbar.addComponent(panHelpToolbar);
pbButton1 = new Button();
pbButton1.setCaption("Button1Text");
pbButton1.setStyleName(BaseTheme.BUTTON_LINK);
pbButton1.setImmediate(true);
pbButton1.setWidth("100px");
pbButton1.setHeight("-1px");
pbButton1.setIcon(new ThemeResource("../images/pic1.gif"));
pbButton1.addClickListener(controller);
panHelpToolbar.addComponent(pbButton1);
panHelpToolbar.setComponentAlignment(pbButton1, Alignment.MIDDLE_LEFT);
pbButton2= new Button();
pbButton2.setCaption("Button2 Text");
pbButton2.setImmediate(true);
pbButton2.setWidth("100%");
pbButton2.setHeight("-1px");
pbButton2.setStyleName(BaseTheme.BUTTON_LINK);
pbButton2.setIcon(new ThemeResource("../images/pic.gif"));
pbButton2.addClickListener(this);
panHelpToolbar.addComponent(pbButton2);
panHelpToolbar.setComponentAlignment(pbButton2, Alignment.MIDDLE_LEFT);
}
Related
Prior to Xcode 9 and iOS 11 I had a UITextView within a UITableViewCell that contained multiple links. Each link worked as expected, however since upgrading to iOS 11 and Xcode 9, the links no longer work.
The UITextView doesn't appear to recognise any touch interaction with func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool never firing.
Has anyone else found this same problem after upgrading?
Turns out there wasn't a problem after all. Changes in the way UITextView responds to touches in iOS11 means that clicking links requires more of a press rather than just a tap which previously worked in iOS10. I think this may be something to do with the fact that in iOS11 you can now press links and drag them which also displays details of URL. So a firmer press is needed for the UITextView to register the link being tapped.
Specifically in iOS 11.0 and 11.1 (not later in 11.2+, not earlier in 10.x), textView(_:shouldInteractWith:in:interaction) from UITextViewDelegate is called from an interaction with a UILongPressGestureRecognizer instead of a UITapGestureRecognizer.
For those two iOS versions, user needs a small delay long press instead of a tap for a native interaction with UITextView links.
If the callback doesn't get called at all for those two iOS versions, even on a long press, you've likely been messing with gesture recognizers by subclassing your UITextView and overriding gestureRecognizerShouldBegin(_) to return false when it shouldn't.
Here is an example of quick partial workaround for gestureRecognizerShouldBegin(_) that will disable loupe/magnifier long press (if that's the desired intent of the override), but still allow long press on links:
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if gestureRecognizer is UIPanGestureRecognizer {
// required for compatibility with isScrollEnabled
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let tapGestureRecognizer = gestureRecognizer as? UITapGestureRecognizer,
tapGestureRecognizer.numberOfTapsRequired == 1 {
// allowing taps for links
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
if let longPressGestureRecognizer = gestureRecognizer as? UILongPressGestureRecognizer,
// allowing small delay long press for links (required for iOS 11.0-11.1)
// average comparison value is used to distinguish between:
// 0.12 (smallDelayRecognizer)
// 0.5 (textSelectionForce and textLoupe)
longPressGestureRecognizer.minimumPressDuration < 0.325 {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
gestureRecognizer.isEnabled = false
return false
}
An alternative is to fully disallow both UILongPressGestureRecognizer and UITapGestureRecognizer except for a self-made UITapGestureRecognizer that you would have build yourself to interact with links.
I have eclipse 3.7 indigo; I installed gwt plugin and its designer; The problem is (time after time) when I add new widget X to composite the
palette (keeps widget selected)
components (doesn't show the new widget in the tree)
properties (doesn't show the new widget properties)
...so I cannot select another widget unless I resize the whole eclipse application to force its GUI repaint :(
It seems like palette and other managers don't get report "widget was added from windowbuilder" or similar :(
Moreover, I cannot edit widget's text if I have input method as "System" which is the default on btw so the only one input method which works is "X Input Method" but anyways it doesn't solve the mentioned focus regain problem;
That makes eclipse indigo really hard to use; So my question is... how to fix that?
p.s.
eclipse 3.7 (indigo)
gwt plugin - https://dl.google.com/eclipse/plugin/archive/3.6.0/3.7
gwt designer - http://dl.google.com/eclipse/inst/d2gwt/latest/3.7
gwt sdk 2.2
jdk 1.7
jre 1.7
OS Linux x64
Thanks
I had to do my own research concerning the issue; I noticed there is some kind of "jobs order conflict" or similar with the default constructor based code style as :
public class MyTestUI extends Composite {
private FlowPanel flowPanel;
public MyTestUI() {
flowPanel = new FlowPanel();
initWidget(flowPanel);
}
}
...so, as a workaround, I had to play with code generator as;
window -> preferences -> windowbuilder -> gwt
(combobox) method name for new statements : initComponents
variable generation : field
statement generation : flat
just to avoid having in-constructor init as a result I have code generated as :
public class MyTestUI extends Composite {
private FlowPanel flowPanel;
public MyTestUI() {
initComponents();
}
private void initComponents() {
flowPanel = new FlowPanel();
initWidget(flowPanel);
}
}
...btw there is a problem with focus regain if input method is "System" and initComponents() method generated first time; so before starting adding widgets I had to select "X input method" to avoid synch-ed jobs; So "X input method" needs to be the default one, as I can get it :)
EDIT :
The effect I faced very looks like bug 388170; So I tried to modify eclipse.ini argument as
-Djava.awt.headless=true
It seems like the headless helps a bit but anyways eclipse sometimes does hang when using windowbuilder especially DnD :P
Anyways I want to point I faced the mentioned issue first time cause similar windows x32 eclipse indigo version works pretty fine with gwt;
p.s.
The solution is not final (the hang problem still occurs on DnD evens) and I am still looking for a more optimal one; So do comment if you have some helpful tips or ideas;
I'm trying to implement an Editor with hint text functionality for a Xamarin.Forms project. This is trivial in Android, because the underlying EntryEditText control has a Hint property. In iOS, the implementation is a bit more complex because the UITextView class does not implement hint text.
I don't like the technique, "set text to the placeholder, clear it if typing starts, return it if typing ends and the text is blank". It means I have to do extra work to tell if the control's blank, and there's a lot of fiddling with the text color involved. But I've been having so much trouble I'm going to have to resort to it. Maybe someone can help me with this.
I started with the answer to Placeholder in UITextView. I started a new Xamarin iOS project and stumbled through a rough Obj-C to C# conversion, and it worked great with a minor change: the Font property of the UITextView isn't initialized yet in the constructor, so I had to override AwakeFromNib() to set the placeholder label's font. I tested it and it worked, so I brought that file into a Xamarin Forms project, and things started getting a little nutty.
The first problem is it turns out apparently MonoTouch has some slight API differences in Xamarin Forms, such as using some types like RectangleF instead of CGRect. This was obvious, if not unexpected. I've been wrestling with some other differences for the past few days, and can't seem to overcome them in a way that makes me happy. Here's my file, trimmed down significantly because I've been trying all kinds of debugging things:
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.CoreGraphics;
using System.Drawing;
namespace TestCustomRenderer.iOS {
public class PlaceholderTextView : UITextView {
private UILabel _placeholderLabel;
private NSObject _notificationToken;
private const double UI_PLACEHOLDER_TEXT_CHANGED_ANIMATION_DURATION = 0.25;
private string _placeholder;
public string Placeholder {
get {
return _placeholder;
}
set {
_placeholder = value;
if (_placeholderLabel != null) {
_placeholderLabel.Text = _placeholder;
}
}
}
public PlaceholderTextView() : base(RectangleF.Empty) {
Initialize();
}
private void Initialize() {
_notificationToken = NSNotificationCenter.DefaultCenter.AddObserver(TextDidChangeNotification, HandleTextChanged);
_placeholderLabel = new UILabel(new RectangleF(8, 8, this.Bounds.Size.Width - 16, 25)) {
LineBreakMode = UILineBreakMode.WordWrap,
Lines = 1,
BackgroundColor = UIColor.Green,
TextColor = UIColor.Gray,
Alpha = 1.0f,
Text = Placeholder
};
AddSubview(_placeholderLabel);
_placeholderLabel.SizeToFit();
SendSubviewToBack(_placeholderLabel);
}
public override void DrawRect(RectangleF area, UIViewPrintFormatter formatter) {
base.DrawRect(area, formatter);
if (Text.Length == 0 && Placeholder.Length > 0) {
_placeholderLabel.Alpha = 1;
}
}
private void HandleTextChanged(NSNotification notification) {
if (Placeholder.Length == 0) {
return;
}
UIView.Animate(UI_PLACEHOLDER_TEXT_CHANGED_ANIMATION_DURATION, () => {
if (Text.Length == 0) {
_placeholderLabel.Alpha = 1;
} else {
_placeholderLabel.Alpha = 0;
}
});
}
public override void AwakeFromNib() {
base.AwakeFromNib();
_placeholderLabel.Font = this.Font;
}
protected override void Dispose(bool disposing) {
base.Dispose(disposing);
if (disposing) {
NSNotificationCenter.DefaultCenter.RemoveObserver(_notificationToken);
_placeholderLabel.Dispose();
}
}
}
}
A notable change here is relocation of the label's initialization from DrawRect() to the constructor. As far as I can tell, Xamarin never lets DrawRect() be called. You'll also note I'm not setting the Font property. It turned out in the iOS MonoTouch project, sometimes the parent's font was null and it's illegal to set the label's font to null as well. It seems at some point after construction Xamarin sets the font, so it's safe to set that property in AwakeFromNib().
I wrote a quick Editor-derived class and a custom renderer so Xamarin Forms could render the control, the Renderer is slightly of note because I derived from NativeRenderer instead of EditorRenderer. I needed to call SetNativeControl() from an overridden OnModelSet(), but peeking at the assembly viewer showed that EditorRenderer makes some private calls I'll have to re-implement in mine. Boo. Not posted because this is already huge, but I can edit it in if needed.
The code above is notable because the placeholder isn't visible at all. It looks like in iOS-oriented MonoTouch, you typically initialize a control with a frame, and resizing is a rare enough circumstance you can assume it doesn't happen. In Xamarin Forms, layout is performed by layout containers, so a constructor-provided frame is irrelevant. However, the size of the label is intended to be set in the constructor, so it ends up having negative width. Whoops.
I assumed this could be solved by moving instantiation of the label into AwakeFromNib(), or at least sizing it there. This is when I discovered that for some reason, AwakeFromNib() isn't called in the control. Welp. I tried to find an equivalent callback/event that happened late enough for the bounds to be set, but couldn't find anything on the iOS side. After trying many, many things, I noticed the custom renderer received property change events for the Xamarin Forms Model side of this mess. So, if I listen for Height/Width change events, I can then call a method on the label to give it a reasonable size based on the current control. That exposed another problem.
I cannot find a way to set the label's font to match the UITextView's font. In the constructor, the Font property is null. This is true in both the iOS and Xamarin Forms project. In the iOS project, by the time AwakeFromNib() is called, the property is initialized and all is well. In the XF project, it's never called, and even when I pull stunts like invoking a method from a 5-second delayed Task (to ensure the control is displayed), the property remains null.
Logic and iOS documentation dictates the default value for the font should be 17-point Helvetica. This is true for the placeholder label if I fudge the size so it's visible. It is not true for the UITextView control, though since it reports its font as null I'm unable to see what the font actually is. If I manually set it all is well, of course, but I'd like to be able to handle the default case. This seems like a bug; the box seems to be lying about its font. I have a feeling it's related to whatever reason the Xamarin.Forms.Editor class doesn't have a Font property.
So I'm looking for the answer to two questions:
If I'm extending an iOS control in XF to add a subview, what is the best way to handle sizing that subview? I've found Height/Width changes raise events in the renderer, is this the only available way?
When the property has not been set by a user, is the Font of a UITextView in Xamarin Forms ever set to a non-null value? I can live with a requirement that this control requires the font to be explicitly set, but it's yucky and I'd like to avoid it.
I'm hoping I've missed something obvious because I started barking up the wrong trees.
If I'm extending an iOS control in XF to add a subview, what is the
best way to handle sizing that subview? I've found Height/Width
changes raise events in the renderer, is this the only available way?
This is the only way I know of since the exposed elements of the renderer are so limited.
When the property has not been set by a user, is the Font of a
UITextView in Xamarin Forms ever set to a non-null value? I can live
with a requirement that this control requires the font to be
explicitly set, but it's yucky and I'd like to avoid it.
No, the Font is not assigned a default non-null value.
Hi noticed some code in our application when I first started Java programming. I had noticed it created a dialog from a separate thread, but never batted an eye lid as it 'seemed to work'. I then wrapped this method up through my code to display dialogs.
This is as follows:
public class DialogModalVisibleThread
extends Thread {
private JDialog jDialog;
public DialogModalVisibleThread(JDialog dialog, String dialogName) {
this.setName("Set " + dialogName + " Visable");
jDialog = dialog;
}
#Override
public void run() {
jDialog.setVisible(true);
jDialog.requestFocus();
}
}
Usage:
WarnUserDifferenceDialog dialog = new WarnUserDifferenceDialog( _tableDifferenceCache.size() );
DialogModalVisibleThread dmvt = new DialogModalVisibleThread( dialog, "Warn User About Report Diffs");
dmvt.start();
Now, as far as I am now aware, you should never create or modify swing components from a separate thread. All updates must be carried out on the Event Dispatch Thread. Surely this applies to the above code?
EDT on WikiPedia
However, the above code has worked.
But lately, there have been countless repaint issues. For example, click on a JButton which then calls DialogModalVisibleThread to display a dialog. It caused buttons alongside the clicked button not to redraw properly.
The repaint problem is more frequent on my machine and not the other developers machine. The other developer has a laptop with his desktop extended onto a 21" monitor - the monitor being his main display. He is running Windows 7 with Java version 1.6.0_27.
I am running on a laptop with Windows 7 and Java version 1.6.0_24. I have 2 additional monitors with my desktop extended onto both.
In the meantime I am going to upgrade to Java 1.6 update 27.
I wondered if the above code could cause repaint problems or are there any other people out there with related paint issues?
Are there any easy ways to diagnose these problems?
Thanks
So, you're breaking a rule, having problems, and wondering if these problems could be cause by the fact that you broke the rule. The answer is Yes. Respect the rules!
To detect the violations, you might be interested by the following page: http://weblogs.java.net/blog/2006/02/16/debugging-swing-final-summary
The easiest way to check if your problems are being caused by breaking the rules is to fix them (You should fix them anyway :-)
Just use SwingWorker.invokeLater() from the thread you want to update to UI from to easily adhere to Swing's contract. Something like this should do the trick:
#Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
jDialog.setVisible(true);
jDialog.requestFocus();
}
});
}
EDIT: You should make the 'jDialog' variable final for this to work.
I am using GWTP. I did the nested presenter tutorial. But there is no tutorial for the SAMPLE TAB application (the one with the admin tab appearing if you switch to the admin mode). Can somebody explain me the main concepts of this application ? Tkx.
Update: Update: Now you can download the workable sample Maven project from here: gwtp-sample-tab.zip
I used the tabbed presenter feature successfully in my project (I found the sample code didn't compile as well). I think the first thing is to make it work, and then learn it and feel the benefits gradually :)
Here is the steps I did:
1) Copy the following files
BaseTab.java
BaseTabPanel.java
SimpleTab.java
SimpleTabPanel.java
SimpleTab.ui.xml
SimpleTabPanel.ui.xml
UiModule.java
from the sample code to you project. For example, I copied to this package: com.widenhome.web.client.ui. Also please remember to configure UiModule in ClientGinjector class.
2) Create a normal presenter (MyPresenter) via GWTP eclipse plugin
3) Change EventBus import this in the presenter
import com.google.web.bindery.event.shared.EventBus;
4) Make sure the MyPresenterView.ui.xml has the following code or similar:
<g:HTMLPanel>
<npui:SimpleTabPanel ui:field="tabPanel" />
<g:SimplePanel ui:field="contentPanel" />
</g:HTMLPanel>
5) Change the presenter to extend TabContainerPresenter instead of Presenter
public class MyPresenter extends
TabContainerPresenter<MyPresenter.MyView, MyPresenter.MyProxy>
6) Define several variables in MyPresenter, or you can just copy/paste the following code:
/**
* This will be the event sent to our "unknown" child presenters, in order
* for them to register their tabs.
*/
#RequestTabs
public static final Type<RequestTabsHandler> TYPE_RequestTabs = new Type<RequestTabsHandler>();
/**
* Fired by child proxie's when their tab content is changed.
*/
#ChangeTab
public static final Type<ChangeTabHandler> TYPE_ChangeTab = new Type<ChangeTabHandler>();
/**
* Use this in leaf presenters, inside their {#link #revealInParent} method.
*/
#ContentSlot
public static final Type<RevealContentHandler<?>> TYPE_SetTabContent = new Type<RevealContentHandler<?>>();
7) Change the constructor of MyPresenter to use the variables:
#Inject
public MyPresenter(final EventBus eventBus, final MyView view, final MyProxy proxy) {
super(eventBus, view, proxy, TYPE_SetTabContent, TYPE_RequestTabs, TYPE_ChangeTab);
}
8) Now we can start to create tab presenters, (e.g MyFirstTabPresenter). Just create a normal presenter again via GWTP eclipse plugin
9) In MyFirstTabPresenter, change MyProxy to let it 'extends' TabContentProxyPlace instead of ProxyPlace
10) Create #TabInfo method, please see javadoc of #TabInfo annotation, you can also use other ways here. For example, I did this:
#TabInfo(container = MyPresenter.class)
static TabData getTabLabel(ClientGinjector ginjector) {
return new TabDataBasic("My First Tab", 0);
}
11) In revealInParent() method of MyFirstTabPresenter class, please make sure it has the following code or similar:
#Override
protected void revealInParent() {
RevealContentEvent.fire(this, MyPresenter.TYPE_SetTabContent, this);
}
That's all related to Tabbed presenter configurations. Now you can add some logic to load some data to show in MyFirstPresenter's view.
I hope this can help you to start with GWTP Tabbed presenter, please let me know any issues you have, I will edit answer gradually and perfect it so that it can help more people to get started with it.
BTW, I also posted this to my blog to help more people on this.
Thanks,
Jiakuan
It doesn't even compile. The only way to trigger multiple presenters in via Nested Presenters - which is tooooo complicated. I built a multiple presenter app with simple GWT History mechanism without any pain. This framework has made GWT History (s aimple mechanism) a very esoteric thing.