as per the material guidelines on transitions, I want to establish a certain look and feel on app screens to convey a hierarchy for these. Meaning, everything that transitions left to right is on same level or importance. Smaller forms or brief user inputs will transition in and out as simple popups, not horizontally but vertically.
Expected behaviour:
The slide form uses the default transition. Show() will slide the source to the left and the destination slides in from the right. showback() will slide the source in from the left and the destination leaves to the right.
The popup form uses a custom transition: show() will cause the source to remaining in place (not slide or transition in any other way) and the destination (the popup) will slide in from below. Showback() will cause the source (the popup) to slide out towards the bottom, revealing the destination (the main window) underneath.
Actual Behaviour
slide form works as expected in my scenario.
show() causes the popup form to slide into the screen from the bottom, while the source form stays in place, being covered up (as expected). BUT the showback() causes the main window to slide in from the top, covering the popup screen.
Full code sample to show actual behavior
public class MyApplication {
private Form current;
private Resources theme;
private Transition defaultInTrans = CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 300);
private Transition defaultOutTrans = CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, true, 300);
private Transition popupInTrans = CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, false, 300);
private Transition popupOutTrans = CommonTransitions.createSlide(CommonTransitions.SLIDE_VERTICAL, false, 300);
public void init(Object context) {
theme = UIManager.initFirstTheme("/theme");
Toolbar.setGlobalToolbar(true);
}
public void start() {
if (current != null) {
current.show();
return;
}
new MainForm().show();
}
public void stop() {
current = getCurrentForm();
if (current instanceof Dialog) {
((Dialog) current).dispose();
current = getCurrentForm();
}
}
public void destroy() {
}
class MainForm extends Form {
public MainForm() {
setLayout(BoxLayout.y());
Button slideBut = new Button("Slide Form");
Button popBut = new Button("Popup Form");
add(slideBut).add(popBut);
slideBut.addActionListener(e -> {
new SlideForm().show();
});
popBut.addActionListener(e -> {
new PopupForm(this).show();
});
}
}
class SlideForm extends Form {
public SlideForm() {
Style bg = getContentPane().getUnselectedStyle();
bg.setBgTransparency(255);
bg.setBgColor(0x00ff00);
getToolbar().setBackCommand("", e -> {
new MainForm().showBack();
});
add(new Label("Slide Form content"));
}
}
class PopupForm extends Form {
public PopupForm(Form orig) {
Style bg = getContentPane().getUnselectedStyle();
bg.setBgTransparency(255);
bg.setBgColor(0xff0000);
getToolbar().setBackCommand("", e -> {
new MainForm().showBack();
orig.setTransitionInAnimator(defaultInTrans);
orig.setTransitionOutAnimator(defaultOutTrans);
});
add(new Label("This is a popup!"));
// remove source animation to remain in place
orig.setTransitionInAnimator(null);
orig.setTransitionOutAnimator(null);
// add transition for target popup to appear and vanish from/to the bottom
setTransitionInAnimator(popupInTrans);
setTransitionOutAnimator(popupOutTrans);
}
}
}
Having different CommonTransition types, the in transition vs the out transition, the transition direction parameterand on top of that the direction of show() vs showback() is quite confusing.
how can I achieve the expected behaviour for the popup form to slide OUT correctly?
is there a better way or less code required to achieve this?
Thank you.
Cover has an in/out effect where slide only has an out effect. When you slide from form A to form B there is one motion including both forms that works exactly the same in reverse. However, with cover it slides on top of form A while the latter stays in place then slides off of it making it look like form A has been under it all along.
That means both transition in and out are used to convey both cover modes. However this can collide with the transition out of form A so we need to temporarily disable it.
E.g.:
removeTransitionsTemporarily(backTo);
f.setTransitionInAnimator(CommonTransitions.createCover(CommonTransitions.SLIDE_VERTICAL, false, 300));
f.setTransitionOutAnimator(CommonTransitions.createUncover(CommonTransitions.SLIDE_VERTICAL, true, 300));
public static void removeTransitionsTemporarily(final Form f) {
final Transition originalOut = f.getTransitionOutAnimator();
final Transition originalIn = f.getTransitionInAnimator();
f.setTransitionOutAnimator(CommonTransitions.createEmpty());
f.setTransitionInAnimator(CommonTransitions.createEmpty());
f.addShowListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent evt) {
f.setTransitionOutAnimator(originalOut);
f.setTransitionInAnimator(originalIn);
f.removeShowListener(this);
}
});
}
Related
I want to be able to add options to a right click menu of the NatTable that when clicked will cause either the row or column headers to be hidden but can be brought back as well.
The common practice is to operate on the corresponding DataLayer and modify the row height. Modifying the IDataProvider is typically not a good practice, as the IDataProvider is responsible for providing the data, not how the data should be rendered. So the following is an example of how to toggle the visibility of the column header layer (supposed that hideHeader is the flag to store the current state).
Button hideButton = new Button(buttonPanel, SWT.PUSH);
hideButton.setText("Hide/Show");
hideButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
this.hideHeader = !this.hideHeader;
if (this.hideHeader) {
columnHeaderDataLayer.setDefaultRowHeight(0);
} else {
columnHeaderDataLayer.setDefaultRowHeight(20);
}
natTable.refresh(false);
}
});
I know users who even used that approach to implement some sort of transition by slowly reducing the height to 0.
Alternatively you could use the RowResizeCommand if the column header DataLayer is not known
Button hideButton = new Button(buttonPanel, SWT.PUSH);
hideButton.setText("Hide/Show");
hideButton.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
this.hideHeader = !this.hideHeader;
if (this.hideHeader) {
natTable.doCommand(new RowResizeCommand(natTable, 0, 0));
} else {
natTable.doCommand(new RowResizeCommand(natTable, 0, 20));
}
}
});
I ended up solving this by changing the logic in the getColumnCount() method in my RowHeaderDataProvider to return 0 when flagged to be hidden, or 1 when flagged to be not hidden. Same applies for the getRowCount() in my ColumnHeaderDataProvider.
I`m using GWT-Popup-Panel with the following code:
private static class MyPopup extends PopupPanel {
public MyPopup() {
// PopupPanel's constructor takes 'auto-hide' as its boolean parameter.
// If this is set, the panel closes itself automatically when the user
// clicks outside of it.
super(true);
// PopupPanel is a SimplePanel, so you have to set it's widget property to
// whatever you want its contents to be.
setWidget(new Label("Click outside of this popup to close it"));
}
}
public void onModuleLoad() {
final Button b1 = new Button("About");
b1.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
final MyPopup g = new MyPopup();
g.setWidget(RootPanel.get("rightagekeyPanel"));
g.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
public void setPosition(int offsetWidth, int offsetHeight) {
g.setPopupPosition(b1.getAbsoluteLeft(), b1.getAbsoluteTop());
g.setAutoHideEnabled(true);
}
});
g.setVisible(true);
g.setWidth("500px");
g.setHeight("500px");
g.show();
}
});
It does appear when clicking Button b1, but not when clicking it the second time. What is wrong?
Make one popup, outside of your ClickHandler, at the same level as your Button. You also don't need that PositionCallback to center your popup. You can just call g.center() to show it and center it. It's a known issue on the GWT support pages that it won't center properly if you don't set a width to it. It will center properly if you give your popup a proper width.
The reason it doesn't show again is because you remove the widget inside RootPanel.get("rightagekeyPanel") and put it into your popup. It is no longer there the next time you try to do it.
A widget can only be in one place at a time, so if you remove it from its parent, keep track of it with a variable or something, so you can re-use it. Otherwise, you must re-instantiate the widget.
public void onModuleLoad() {
final Button b1 = new Button("About");
final MyPopup g = new MyPopup(); //create only one instance and reuse it.
g.setAutoHideEnabled(true);
g.setSize("500px", "500px"); //sets width AND height
b1.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
g.setWidget(RootPanel.get("rightagekeyPanel"));//DON'T DO THIS.
g.center();//will show it and center it.
}
});
}
Just say in my case I had to add some widget to make the PopUpPanel appear. Try using a label to make sure the Popup is showing.
PopupPanel popup = new PopupPanel();
popup.setVisible(true);
popup.center();
popup.show();
popup.setWidth("500px");
popup.setHeight("500px");
popup.add(new Label("Test"));
I have a window resizeHandler, it is working fine. Except that I'm just interested in the final dimension of the window, in other words, I'm interested in the dimension of the window when the mouse button is released. Is there a way I can listen to window mouse events?
I've written a piece of code that accomplishes my goal but I'd prefer something more obvious. resizeRequestId is a field:
private void processResize() {
final Timer timer = new Timer() {
final Size windowSize = getWindowDimention();
final int requestId = ++resizeRequestId;
#Override
public void run() {
final boolean isLatestRequest = requestId == resizeRequestId;
if (isLatestRequest) {
//DO SOMETHING WITH windowSize
}
}
};
timer.schedule(100);
}
The browser doesn't pass along events that happen outside of the page, and the window resize counts as outside the page. That said, you still get a hook for resize actions of the entire browser window:
Window.addResizeHandler(new ResizeHandler() {
public void onResize(ResizeEvent event) {
//get, process window resize behavior
}
});
For some browsers and some resizes, you'll get lots of events as the mouse moves, and for others, you'll only get the complete one. In firefox, for example, the resize handle in the corner sends every change that is made, while the side handles each send only once the user releases the mouse. Minimizing and maximizing the window also result in a single event.
Colin is right.
Moreover, if you do a lot of calculations "on resize" (e.g. forceLayout), it is a good idea to add a Timer. This way the calculations will be fired once every...10th of second?
final Timer resizeTimer = new Timer() {
#Override
public void run() {
mainPanel.forceLayout();
}
};
Window.addResizeHandler(new ResizeHandler() {
public void onResize(ResizeEvent event) {
int height = event.getHeight();
mainPanel.setHeight(height + "px");
resizeTimer.cancel();
resizeTimer.schedule(100);
}
});
That's it
I have view that extends ViewPart. In this view, I want to add toolbar menu.
What I know, we can add toolbar menu by using ActionContributionItem or Action, and add it to ToolBarMenu from createPartControl method in ViewPart.
But what I don't know is this: How can we disable/enable the toolbar menu programmatically?
So basically, I want to add Play, Stop, and Pause button to toolbar view. So at first, the Play button is on enabled mode, and the others are disabled. When I pressed Play button, it is disabled, and others will be enabled.
For more details, what I want to achieve is something like the following image.
In the red circle are disabled button, and in the blue circle are enabled button.
Instead of using Actions, have a look at Eclipse commands (they are the replacement for actions and function in a cleaner way): http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/guide/workbench_cmd.htm
You will see in the documentation that you can enable and disable a command and all places where it's used will properly update their state automatically.
There is another approach which I found by stumbling upon on google. This approach is using ISourceProvider to provide variable state. So we can provide the state of enablement/disablement of command in that class (that implementing ISourceProvider). Here is the detail link http://eclipse-tips.com/tutorials/1-actions-vs-commands?showall=1
Try this..
1: Implement your actions. ex: PlayAction, StopAction.
Public class StartAction extends Action {
#Override
public void run() {
//actual code run here
}
#Override
public boolean isEnabled() {
//This is the initial value, Check for your respective criteria and return the appropriate value.
return false;
}
#Override
public String getText() {
return "Play";
}
}
2: Register your view part(Player view part)
Public class Playerview extends ViewPart
{
#Override
public void createPartControl(Composite parent) {
//your player UI code here.
//Listener registration. This is very important for enabling and disabling the tool bar level buttons
addListenerObject(this);
//Attach selection changed listener to the object where you want to perform the action based on the selection type. ex; viewer
viewer.addselectionchanged(new SelectionChangedListener())
}
}
//selection changed
private class SelectionChangedListener implements ISelectionChangedListener {
#Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = Viewer.getSelection();
if (selection != null && selection instanceof StructuredSelection) {
Object firstElement = ((StructuredSelection)selection).getFirstElement();
//here you can handle the enable or disable based on your selection. that could be your viewer selection or toolbar.
if (playaction.isEnabled()) { //once clicked on play, stop should be enabled.
stopaction.setEnabled(true); //Do required actions here.
playaction.setEnabled (false); //do
}
}
}
}
Hope this would help you.
I am new to GWT and the web stuff.
I am working out my own project based on
http://code.google.com/p/cloud-tasks-io/source/browse/#svn%2Ftrunk%2FCloudTasks-AppEngine%2Fsrc%2Fcom%2Fcloudtasks%2Fclient
I am trying to use popup/dialog. The popup and dialog always show behind the widget. I keep googling around and the most relevant I found is this
http://groups.google.com/group/gwt-google-apis/browse_thread/thread/40db4fcbe10d2060 which does not provide any answer. Anyway, I have 3rd party library, bst-player 1.3, which uses flash. So I disabled it(later remove it too), the popup just won't come to the top! It is still hiding behind the widget.
I have learned that popuppanel/dialogpanel alikes do not need to get added to another widget. A different way of saying is that it is not a normal widget in a sense that it cannot attach to a parent but it attaches itself to the dom to guarantee being on top (from GWT composite widget )
I am at my wit end and I am here at SO ...
UPDATE
Here is my Popup class
public class PopUp {
static PopupPanel simplePopup;
public static void init() {
simplePopup = new PopupPanel(true);
simplePopup.hide();
simplePopup.setVisible(false);
// DOM.setIntStyleAttribute(simplePopup.getElement(), "zIndex", 3);
}
public static void showpopupmsg(String msg, int left, int top) {
if (simplePopup == null) {
init();
}
if (msg != null && !msg.equalsIgnoreCase("")) {
simplePopup.ensureDebugId("cwBasicPopup-simplePopup");
simplePopup.setWidget(new HTML(msg));
simplePopup.setVisible(true);
simplePopup.setPopupPosition(left, top);
simplePopup.setWidth("475px"); //575
simplePopup.setGlassEnabled(true);
simplePopup.show();
}
}
public static void show(String message){
if (simplePopup == null) {
init();
}
simplePopup.setGlassEnabled(true);
simplePopup.setTitle(message);
simplePopup.center();
}
}
Here is how I am calling
tasksTable.doneColumn.setFieldUpdater(new FieldUpdater<TaskProxy, Boolean>() {
public void update(int index, TaskProxy task, Boolean value) {
String msg = "Here is the popup. All the way underneath";
Widget source = tasksTable;
int left = source.getAbsoluteLeft() - 50;
// source.getAbsoluteLeft() + 25;
int top = source.getAbsoluteTop() - 25;
PopUp.showpopupmsg(msg, left, top); //Here is the calling method
TaskRequest request = requestFactory.taskRequest();
TaskProxy updatedTask = request.edit(task);
updatedTask.setDone(value);
request.updateTask(updatedTask).fire();
}
});
Here is how the Popup is beneath the widget.
The source of the problem has been quite elusive since I am still new to the webapp, yet, I finally solve it myself. The culprit is the CSS. It is defining the z-index for the whole thing to quite high as seen in the following code line 1333.
http://code.google.com/p/cloud-tasks-io/source/browse/trunk/CloudTasks-AppEngine/war/CloudTasks.css#1333
I have doubted about the z-index before and try it out with a paltry value 3 as seen in the commented out code segment of Popup class in question. I have to uncomment it and set it to 101.
DOM.setIntStyleAttribute(simplePopup.getElement(), "zIndex", 101);
I was , you know, #$%###$*.
z-index is only decides which widget should show on top..
the widget popup is under benath might be having z-index value high.
set the z-index for popup thru css (recomended) or DOM will work for you
According to my feeling, using static methods of your "PopUp" object is a bit strange...
In that way, I think things a relative to the top rather than caller object.
Maybe you could consider make your class 'Popup' extending 'popupanel'
and in your calling code, just make
new PopUp(msg,left,top).show() ;
I recently wrote my own solution for a popup panel that needs to be aligned with its caller. The solution consists out of an PopupPanel extension and a Button extension.
The button extension has an instance of the panel extension, and the moment it is clicked it gives its coordinates and width and height to its panel.
#Override
public void onClick(ClickEvent event) {
if (optionsPanel.isShowing()) {
optionsPanel.hide();
} else {
optionsPanel.setButtonBounds(new Bbox(
getAbsoluteLeft(), getAbsoluteTop(), getOffsetWidth(), getOffsetHeight()));
optionsPanel.show();
}
}
(The Bbox class is just a convenience class I could use for wrapping coordinates; write your own class or 4 methods for that matter)
The main work is then done in the onLoad() override of the PopupPanel, in which the coordinates of the button are used to position the panel;
#Override
protected void onLoad() {
super.onLoad();
if (null == bounds) {
super.hide();
} else {
left = (int) bounds.getX();
top = (int) bounds.getMaxY();
setPopupPosition(left, top);
}
}
(bounds are the coordinates of the button; getMaxY() == bottom coordinate of button)