Can not open FXML after a while - javafx-8

I have a problem with my JavaFX Scene Builder v2.0-b14.
From time to time, the FXML can't get opened. Even if i remove everything from the FXML except the root.
In the taskbar, it looks like this:
If i rename the File, i can open the FXML normally.
Does anyone know/had this problem, or know where the SceneBuilder caches such things?
greetings,
Kalasch

Even though this question has been asked long time ago and it already got an accepted answer, I want to contribute my solution to this problem because it differs from the other solutions and in addition is very simple.
This particular problem happened to me just a few mins ago and all I took to solve was:
Windows XP/7
Opening the Windows Taskmanager
Switch to the applications tab
Right click the SceneBuilder (named: yourFileName.fxml)
Select 'Maximize'
Windows 8+
Opening the Windows Taskmanager
Switch to Processes Tab
Click the dropbown for JavaFX Scene Builder x.x.exe
Find the FXML file that is not opening
Right-Click > Press Maximize
Description above works for Windows OS, on other OS the corresponding application managing program should do the same.
That worked for me just perfect. No copying and/or overwriting needed.

A simple workaround is:
copy the fxml in some other place
open it
save it to the original place(overwrite old)
That is just a workaround, but works.
It would be great if some other, better solution is found for this.

So try this:
Copy your fxml file in some other place. Open JavaFx scen builder and create your scene (some very simple'even with only anchor pane and one label or something ) and save in the place of your fxml on the project. Now try if you can open this by double click. If yes, just copy xml from your orginal file and replace the xml in the that you just created.

I had this same problem and here's how I've managed to solve it.
Open JavaFX Scene Builder.
Drag and drop the file from the Eclipse (or Netbeans) into Scene Builder.
Edit the scene that you opened.
Now, click File -> Save as... -> Choose the location of yout FilterBox.fxml file and overwrite it.
Now you are able to open *.fxml file in Netbeans just by doble-click on the file

I ran in to this several times while using Netbeans, sometimes when it was opened in the Netbeans editor it added extra namespace declarations in the root element.
e.g.
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" id="AnchorPane" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1">
<children>
</children>
</AnchorPane>
Deleting the second instance of the namespace allowed it to be openend and loaded properly again every time.

As Kalaschni said:
A simple workaround is:
copy the fxml in some other place
open it
save it to the original place(overwrite old)
works ok on win 8.1 and win 7 but u lose your relative paths to CSS and so on ...
and as ifLoop said:
Opening the Windows Taskmanager
Switch to the applications tab
Right click the SceneBuilder (named: yourFileName.fxml)
Select 'Maximize'
works on Win8.1 and 7 ... no other side effects :) wishi could comment this but dont have enough reputation ...

Best way is:
Open Scene Builder from Desktop
Go to File -> Open Recent
Click on Clear Menu

Thanks you ifloop and Dean Meehan. You helped me find my solution:
private Stage stage;
private Preferences prefs = Preferences.userNodeForPackage(getClass());
#Override
public void start(Stage stage) throws Exception {
this.stage = stage;
...
double x = prefs.getDouble("X", 0);
double y = prefs.getDouble("Y", 0);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// The following four lines of code return the application to the screen.
if(x<0 || x>screenSize.getWidth())
x = 0;
if(y<0 || y>screenSize.getHeight())
y = 0;
stage.setX(x);
stage.setY(y);
...
stage.show();
}
#Override
public void stop() throws Exception {
...
double x = stage.getX();
double y = stage.getY();
// if the window has been minimized, you will get x = -32000.0 and y=-32000.0
if(x>=0)
prefs.putDouble("X", x);
if(y>=0)
prefs.putDouble("Y", y);
}

Related

Drag a file from my GTK app to another app (not the other way around)

I have searched for examples, but all the examples were the opposite direction (my app is getting file drag-and-drop from another application). But this must be possible because I can drag a file from Files (Nautilus) to another app, Text Editor (gedit).
Could you show me a very simple example of a GTK Window with one widget on it, and when I drag from the widget to Text Editor, it passes a text file on the system (such as /home/user/.profile) to the Text Editor so that it will open the text file?
In order to make it so that your application can receive files, you need to use uri. In the function you bind to drag-data-received, you can use data.get_uris() to get a list of the files that were dropped. Make sure that you call drag_dest_add_uri_targets(), so that the widget can receive URIs.
This code example has one button that drags a file, and another button that can receive it. You can also drag the file and drop it into any file-receiving app, such as gedit (Text Editor) or VSCode.
import gi
gi.require_version("Gdk", "3.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, Gdk
window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)
box = Gtk.HBox()
window.add(box)
# Called when the Drag button is dragged on
def on_drag_data_get(widget, drag_context, data, info, time):
data.set_uris(["file:///home/user/test.html"])
# Called when the Drop button is dropped on
def on_drag_data_received(widget, drag_context, x, y, data, info, time):
print("Received uris: %s" % data.get_uris())
# The button from which the file is dragged
drag_button = Gtk.Button(label="Drag")
drag_button.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, [], Gdk.DragAction.LINK)
drag_button.drag_source_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drag_button.connect("drag-data-get", on_drag_data_get)
box.add(drag_button)
# The button into which the file can be dropped
drop_button = Gtk.Button(label="Drop")
drop_button.drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.LINK)
drop_button.drag_dest_add_uri_targets() # This makes sure that the buttons are using URIs, not text
drop_button.connect("drag-data-received", on_drag_data_received)
box.add(drop_button)
window.show_all()
Gtk.main()
Mr Kruin's answer was for Python's GTK. The language I actually wanted was C#. Using his code as a hint, I modified the default GtkApplication project like so, and it worked on Linux.
private MainWindow(Builder builder) : base(builder.GetRawOwnedObject("MainWindow"))
{
builder.Autoconnect(this);
DeleteEvent += Window_DeleteEvent;
_button1.DragDataGet += (o, args) =>
{
args.SelectionData.SetUris(new string[]{fullFilePath});
};
Gtk.Drag.SourceSet(_button1, Gdk.ModifierType.Button1Mask,
new TargetEntry[0],
Gdk.DragAction.Link);
Gtk.Drag.SourceAddUriTargets(_button1);
}
On Windows, however, it did not work. I have tried both string fullFilePath = "file:///c:/windows/win.ini" and string fullFilePath = "c:\\windows\\win.ini" and none of them seemed to work.

Problem: VSCode DefinitionProvider opens the same document every time in a new tab

I have implemented DefinitionProvider, but it opens the same document every time in a new tab when navigating by definition. Too many tabs after a certain period of time. Does anyone know how to override this behavior?
Thank you for any tips.
What looks suspicious to me is this line in your code:
...
Uri.parse(doc.uri + '#' + item.name),
...
Maybe adding a fragment to the original document URI makes VS Code think that each definition has to be opened in a separate editor.

Eclipse: Perform an action any time an editor receives input

I'm wondering if it is possible to determine what input was just entered inside of an editor in Eclipse - I'm currently working off of the example JDT editor - and then perform an action based on that input.
e.g.: I have a file example.jav open in my editor window. I push the 'a' key. 'a' would appear in the editor window per normal, but 'a' would also print out to the console.
Obviously the operation I'll be performing will be more complicated than a System.out.println() statement, but if someone could help show me where the change gets detected by the editor itself, I can take it from there.
A few notes:
I'm working in Eclipse 3.7.2 with Java 1.7
If you cannot find the JDT example editor, go to Help > Welcome > Samples and click on "Java Editor".
Thanks in advance!
Figured it out!
As the Editor API is so vast in eclipse that it is difficult to know where to start, I focused on adding a KeyListener to my Shell. Turns out that is slightly problematic in SWT, as when an item inside the Shell gains focus, the Shell itself looses focus. After a bit of searching though, I stumbled across someone else who had the same problem. By adding a filter to the Shell's display, you can add a Listener object which works for the entire application. Such as:
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Shell shell = window.getShell();
shell.getDisplay().addFilter(SWT.KeyDown, new Listener()
{
public void handleEvent(Event event)
{
System.out.println("" + event.character);
}
});
To further this and only worry about keys pressed in a specific non-widget part (otherwise you could just add a KeyListener to that part) you can add a check to make sure that the currently active part is the same as whatever part you wish to perform the actions for by using a simple if check.
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
Shell shell = window.getShell();
shell.getDisplay().addFilter(SWT.KeyDown, new Listener()
{
public void handleEvent(Event event)
{
IWorkbenchPage page = window.getActivePage();
IWorkbenchPart part = page.getActivePart();
IEditorPart editor = page.getActiveEditor();
if(part.equals(editor))
{
System.out.println("" + event.character);
}
}
});
Here is hoping that this helps someone else have an easier time than I had finding the solution!

e4 dynamic menu contributions

This feature has been realized as of Kepler M4, for a detailed information on the usage see my blog
I want to realize a fully dynamic menu contribution to the menu of a handler located in a view toolbar. In Eclipse 3 it was possible to add "dynamic" as org.eclipse.ui.menus contribution to a Menu!
I already found out about www.vogella.com/blog/2010/10/26/processors-e4-model explaining on how to dynamically contribute to menus by means of processor model extensions but I am talking about a completely dynamic menu implementation which changes on every call of the resp. submenu. As mentioned this was no problem to realize in Eclipse 3.x via the dynamic menu contribution and the set of isDynamic() to true.
I already tried several approaches:
Registering a processor hooking to a menu => no dynamic add possible (new elements are simply not shown, also discussed in Eclipse Forum - Cannot replace menu items at runtime)
Listening to the UIEventTopic for the event of creating the menu, getting the widget for Modification => modifications to the swt.Menu gathered are simply ignored (every listener, element etc.) (for info RCP Event Model
Open, untried solutions
Inserting a ToolControl to try an SWT approach -> quite complicated but may work
I've been banging my head for some time now, but can't seem to understand the correct implementation of this problem within E4.
-- This question was also asked in Eclipse Forum - Dynamic menu contributions
----- UPDATE
I tried a different approach up to now:
I added a HandledToolItem to the Menu (please see the following image)
and with the following code I am trying to interfere with the menus way to build, where the code is called by the resp. command handleer as referenced in the image.
#CanExecute
public boolean canExecute(#Optional MApplication application) {
System.out.println("CanExecute Counter="+counter);
// --- 1 ---
// Find the required MMenu Entry in the Application Model
if(application == null) return true;
EModelService modelService = (EModelService) application.getContext().get(EModelService.class.getName());
MPart part = (MPart) modelService.find("at.medevit.emr.contacts.ui.contactselector", application);
List<MToolBarElement> lmte = part.getToolbar().getChildren();
HandledToolItemImpl htil = null;
for (MToolBarElement mToolBarElement : lmte) {
if(mToolBarElement.getElementId().equals("at.medevit.emr.contacts.ui.contactselector.toolbar.handledtoolitem.filter")) htil = (HandledToolItemImpl) mToolBarElement;
}
if(htil != null) {
MMenu elemMenu = htil.getMenu();
// --- 2 ---
// Found it hopefully, let's start the real work, simply add a new item
MDirectMenuItem mdi = MMenuFactory.INSTANCE.createDirectMenuItem();
mdi.setLabel("Counter "+counter);
counter++;
// --- 3 ---
elemMenu.getChildren().add(mdi); // ConcurrentModificationException
}
As one can see, this code is queried once the menu is created, to determine whether the command is executable or not. All the code from 1 - 2 is to find the correct MMenu element to work on. The code from 2 - 3 creates a MenuItem and increments a counter in the field.
BUT at 3 I face a java.util.ConcurrentModificationException the first time the menu is opened! I assume that at this very point the menu is iterating over elemMenu.getChildren() and I am not allowed to enable!
So whats all the fuzz about the entire e4 model being changeable all the time ;) (just kiddin' I know this is a baaaad hack!!!)
Thing is: I really think that the possibility to add fully dynamic menu parts is one of the best usability tools, and if it is not possible to realize it in E4 as it was in E3 this is a very serious degradation of possibilities!!!
-- UPDATE
An Eclipse Bug has been filed for this https://bugs.eclipse.org/bugs/show_bug.cgi?id=389063
Proper dynamic model updates should be handled in the bug you've opened. As a workaround in Eclipse4 in Juno, a MRenderedMenuItem can be created in Eclipse4 to provide the equivalent functionality to the dynamic element (although if you are using 4.2, you would just use org.eclipse.ui.menus).
ex:
ContextFunction generator = new ContextFunction() {
#Override
public Object compute(IEclipseContext context) {
return new MyCompoundContributionItem(context);
}
};
MRenderedMenuItem menuItem = MenuFactoryImpl.eINSTANCE.createRenderedMenuItem();
menuItem.setElementId(id);
menuItem.setContributionItem(generator);
container.getChildren().add(menuItem);
This effectively provides a CompoundContributionItem directly to the Eclipse4 menu renderer.

How to redirect key presses to another shell in an Eclipse-based app?

I'm working on a way to maximise an EditorPart in my Eclipse-based RCP app to be absolutely full-screen, no trim, no menu, and so on. Actually, it's a GEF Editor. It's a bit of a hack, but it kind of works:
GraphicalViewer viewer = (GraphicalViewer)getWorkbenchPart().getAdapter(GraphicalViewer.class);
Control control = viewer.getControl();
Composite oldParent = control.getParent();
Shell shell = new Shell(SWT.APPLICATION_MODAL);
shell.setFullScreen(true);
shell.setMaximized(true);
// Some code here to listen to Esc key to dispose Shell and return...
shell.setLayout(new FillLayout());
control.setParent(shell);
shell.open();
Basically it sets the parent of the GraphicalViewer control to the newly created, maximised Shell. Pressing escape will return the control to it's original parent (code not shown for brevity).
The only thing that doesn't work is receiving global key presses (Del, Ctrl+Z, Ctrl+A) the ones that are declared for the Workbench and forwarded to the EditorPart. Is there any way I can hook into these or redirect them from the EditorPart to forward them on to the GraphicalViewer?
Thanks in advance
The short answer is you can't do that. Once you re-parent that composite out of the workbench window, it's totally busted. The system won't correctly deal with the part, as events (like activation, focus, setBounds(*)) aren't being processed.
The only supported way would be to open a new Workbench window with a perspective that only contained the editor area, and extending your org.eclipse.ui.application.WorkbenchWindowAdvisor.createWindowContents(Shell) method for that window+perspective combination to hide all of the trim you don't want, using org.eclipse.ui.application.IWorkbenchWindowConfigurer.
ex, in MyWorkbenchWindowAdvisor:
public void createWindowContents(Shell shell) {
if (isCreatingSpecialPerspective()) {
final IWorkbenchWindowConfigurer config = getWindowConfigurer();
config.setShowCoolBar(false);
config.setShowFastViewBars(false);
config.setShowMenuBar(false);
config.setShowPerspectiveBar(false);
config.setShowProgressIndicator(false);
config.setShowStatusLine(false);
}
super.createWindowContents(shell);
}
Also check out http://code.google.com/p/eclipse-fullscreen/ which has EPLed code in it concerned with running an RCP program with fullscreen support.
My suggestion is to try to approach this problem from another angle. Instead of listening for keystrokes in your code and acting upon them, define your own key binding scheme and then create commands and make them use this scheme. This would mean that you no longer have to listen for the key strokes in your code, but instead do whatever needs to be done through commands executed by these key strokes.