I have downloaded the Vaadin Colorpicker addon to try it out , there is a small problem if i klick the colorPicker "Button" twice i get an IllegalArgumentException :
Exception
java.lang.IllegalArgumentException: Window was already added to application - it can not be added to another window also.
at com.vaadin.ui.Window.addWindow(Window.java:1447)
at com.vaadin.addon.colorpicker.ColorPicker.changeVariables(Unknown Source)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1299)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1219)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:735)
Another question :
I want the colorPicker window to popup if I click on an item in a Menu something like if i click on "set Color" i get the colorPicker window. its quite hard to place the button on my GUI :P
EDIT :
Im adding the ColorPicker like this :
colorPicker = new ColorPicker();
colorPicker.setButtonCaption("Set Color");
colorPicker.setRGBVisibility(false);
colorPicker.setHSVVisibility(false);
colorPicker.setHistoryVisibility(false);
colorPicker.addListener(this);
window.addComponent(colorPicker);
I think you should try this code in your application:
public class MyApplication extends Application {
#Override
public void init() {
Window mainWindow = new Window("Your Application");
// Create a color picker
ColorPicker cp = new ColorPicker("ColorPicker", Color.RED);
// Add a color change listener to the color picker
cp.addListener(new ColorPicker.ColorChangeListener() {
#Override
public void colorChanged(ColorChangeEvent event) {
MyApplication.this.getMainWindow()
.showNotification("Color changed!");
}
});
mainWindow.addComponent(cp);
setMainWindow(mainWindow);
}
}
If it doesn't work, then there is a defect in ColorPicker (and you could report a defect here: http://dev.vaadin.com/).
If the code above works, the problem is in your code then (in this case, share with us more of your code - you can even share whole class for).
Related
How to show ColorPicker from my action in IntelliJ IDEA plugin DevKit?
For example I have an action:
public class TextBoxes extends AnAction {
public void actionPerformed(AnActionEvent event) {
// Some code
}
}
In which I want to display ColorPicker widget:
ColorPicker colorPicker = new ColorPicker(args); // Like that
ColorPicker.showDialog(args); // Or like that
In new ColorPicker(args) format there is a Disposable parent object required. Where should I get this one?
In ColorPicker.showDialog(args); there is also a Component parent object required. And again I can't understand where should I get this object?
And which one is the right way to display ColorPicker from com.intellij.ui.ColorPicker package?
Please do it like this:
public class TextBoxes extends AnAction {
#Override
public void actionPerformed(AnActionEvent event) {
Color color = ColorPicker.showDialog(...)
}
}
I'm having issues when I change my theme, I have a default theme and a theme called Blue, I change to Blue by pressing a button then it's working good untill I get back to my main Menu then it changes back to my default theme by overriding my Blue theme. I want to avoid it.
This is my initVars:
protected void initVars(Resources res){
Toolbar.setOnTopSideMenu(false);
}
This is my button to do the change:
#Override
protected void onMain_Button4Action(Component c, ActionEvent event) {
UIManager.initNamedTheme("/theme", "Blue");
Display.getInstance().getCurrent().refreshTheme();
}
And this is my button function to back to my main Menu:
back.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
new StateMachine("/theme");
}
});
Should I set something in initVars or in my ActionListener to avoid overriding?
I would suggest staring over with a new project. You are using the old GUI builder which is deprecated.
Assuming both themes are in the main res file you don't need to do that. You just need a reference to the resource file which you can get in the old GUI builder using fetchResourceFile().
Hashtable themeData = theme.getTheme("Theme Name");
UIManager.getInstance().setThemeProps(themeData);
Display.getInstance().getCurrent().refreshTheme();
I have tried searching for this many times with no luck. I am writing a software where I want the user to input their resolution before moving on to the main UI, as the main UI will change size based on the resolution given. How would I open a popup window without a button event handler and then proceed to the main application?
You can just open the popup window in your start() method:
public class MyApp extends Application {
#Override
public void start(Stage primaryStage) {
// make sure application doesn't exit when we close the dialog window:
Platform.setImplicitExit(false);
Stage popup = new Stage();
TextField resolutionField = new TextField();
// ... populate popup, etc...
popup.setOnHidden(() -> {
int resolution = Integer.parseInt(resolutionField.getText());
// now create main UI...
primaryStage.show();
});
popup.show();
}
}
I'm currently developing an app, and for this, I'm using Java RCP with SWT.
What I want :
I have a window, and when I click on a Button, i need a whole window to be opened. The window works perfectly and looks like this :
Window1
When I press it, a new window opens. It looks like this :
Window2 (Yup, the middle pic has its importance)
How it's currently done :
The Window 1 is a TrimmedWindow done with the Application.e4xmi, with some Parts in. The button is included in one of these parts. Here's its code :
#PostConstruct
public void postConstruct(Composite parent) {
Button b = new Button(parent, SWT.BORDER);
b.setText("Press me !");
b.addListener(SWT.Selection, new Listener() {
#Override
public void handleEvent(Event event) {
parent.getShell().dispose();
new Game(Display.getCurrent());
}
});
}
The Window 2, as you can see, is a new class called Game. Its constructor is as follows :
public Game(Display display) {
this.display = display;
this.shell = new Shell(this.display);
this.setData();
shell.setText("I don't work properly");
shell.setMinimumSize(800, 600);
this.buildUI();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!this.display.readAndDispatch ()) this.display.sleep ();
}
this.display.dispose ();
}
What's the problem ? :
When I launch the project with Eclipse, everything goes WELL. I mean, really. I click, it opens, it loads, yay ! But the idea after this is I export the project as an executable. So I do it. Here's my .exe file. And let's start. And it doesn't work. When I press the button, nothing happens. Not even an error message, nothing.
I've found some solution that says the problem comes from the display, because RCP is single threaded. So I followed the instructions, and here's another version of the Game constructor :
public Game() {
this.display = Display.getDefault();
this.display.asyncExec(new Runnable() {
#Override
public void run() {
shell = new Shell(display);
setData();
shell.setText("I work better but...");
shell.setMinimumSize(800, 600);
buildUI();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
});
}
And so here comes the new problem : I can't call an Image after this (hence the pic I showed on Window 2). Because Image (SWT) requires a display to be constructed, and because display doesn't work well without the Runnable instance, I can't use an image after this. And I need my Image here (and also somewhere else after this).
Edit : I have an error message in that case. It says :
org.eclipse.swt.SWTException : Failed to execute runnable
(java.lang.IllegalArgumentException : Argument cannot be null)
Any solutions anyone please ?
Thanks in advance.
Kosnyru.
If you add a Trimmed Window (or just a plain Window) to the 'Windows and Dialogs' section of the Application.e4xmi with 'To Be Rendered' turned off (leave Visible on) you can then show it using:
#Inject
EModelService modelService;
#Inject
MApplication app;
MUIElement window = modelService.find("window id", app);
window.setToBeRendered(true);
If the button is clicked, I want to add a Label to page and fade it in via an CSS animation. I thougt, I could just create and add the label with the CSS class "hidden" attached, which has the opacity = 0 and after that remove the class and CSS will do the rest.
But i was wrong. GWT seems to execute the code in the onClick() in some kind of bulk mode -> The label gets added already without the "hidden" class. How can i prevent or do it that better? If I add/remove the "hidden" class manually in the browser, the animation works finde.
The java code looks like this:
Button submitButton = new Button("send");
submitButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Label l = new Label("test");
l.addStyleName("hidden");
RootPanel.get().add(l);
l.removeStyleName("hidden");
}
});
RootPanel.get().add(submitButton);
Das CSS sieht folgendermaßen aus:
.gwt-Label{
transition-property: opacity;
transition-duration: 1s;
}
.hidden{
opacity:0;
}
Probably you have to add some delay function before remove hidden class.
Here you have example (in JS but it's only to show):
http://jsfiddle.net/matku/PXnPZ/
$(".myElement").delay(50).queue( function(){
$(this).removeClass("hidden");
});
And another way I found on google:
http://map-notes.blogspot.com/2012/11/fade-animation.html