extension of eclipse XMLMultiPageEditorPart - trigger refresh of tree-view manually - java

I am working on an eclipse-plugin which makes use of a custom XMLMultiPageEditor by extending XMLMultiPageEditorPart and XMLTableTreeView by extending XMLTableTreeViewer the second one as well implements a IResourceChangeListener.
I provide this plugin in eclipse-mars and eclipse-neon, however the wired behavior only shows up in eclipse-neon.
The editor works fine so far, the only problem is, that the tree-view is completely blank when a related xml-document is opened with it:
I can even modify the document in the source-view and save it .. the tree-view stays blank.
The only events which bring the tree-view to life are:
re-size the editor-window with the mouse
open some other document and than switch back to the tab of the open xml-doc.
After that, the tree-view works like it should. If I now change the xml in the source-view, the tree-view is updated immediately.
Any ideas how I could trigger a refresh of the tree-view manually ?
Is this maybe a bug in eclipse-neon ?

Ok, the problem seems to be, that the x/y size of the TreeViewer in eclipse-neon is initialized with (0,0). Here a hack to fix that:
...
public class MyXMLTableTreeViewer extends XMLTableTreeViewer implements IResourceChangeListener{
....
public MyXMLTableTreeViewer(Composite parent, IEditorPart parentEditor)
{
super(parent);
....
Point size = getControl().getSize();
size.x = 1000;
getControl().setSize(size);
}
It seems to be sufficient to only set x to some value ... 10 already gives an image, but the "node" section than looks a bit pressed, so I picket 1000.
Even if it is just internal API, it looks like a bug for me. So if you are further interested, take a look to the eclipse bugreport.

Both XMLMultiPageEditorPart and XMLTableTreeViewer are in internal packages. This means that they are not part of the Eclipse APIs and can be changed by the Eclipse developers without warning (see Eclipse API Rules of Engagement).
It may well be the case that something was changed between Eclipse Mars and Neon. You cannot rely on internal classes working the same between releases. It is not an Eclipse bug because you are not using official APIs.

Related

Create a MultipageEditor for XML

I am working on an eclipse Plugin, and I would like to use an Editor, set some listeners on the current page(good terminology?), and remove these listeners when the user switches on another page (basically, the user is editing several files, as you could do with the default JAVA editor).
For the moment I have written a class extending StructuredTextEditor. The behavior of the plugin was the one expected, but when I try to work on several files, many problems occur. The main problem, according to me, is that I am not able to get notified when the user opens another page.
I read (and tested) a few things about MultiPageEditor, but it seems like it doesn't integrate an XML editor as default editor. How should I proceed in order to get a MultiPageEditor, with XML syntax coloring, and get notified when the user changes the current page to adjust my listeners ?
Thanks for reading.
the code is not perfect but at least you will have an example of a MultiPageEditor integrating an XMLEditor: https://github.com/fusesource/fuseide/blob/8.0.0.Beta2/editor/plugins/org.fusesource.ide.camel.editor/src/org/fusesource/ide/camel/editor/CamelEditor.java
The idea is to call addPage(new StructuredTextEditor()) inside createPages() method.
regards,
In your editor you can listen to selection changes in the editor text using:
getSelectionProvider().addSelectionChangedListener(listener);
where listener implements ISelectionChangedListener.
This applies to any editor derived from AbstractTextEditor (which includes StructuredTextEditor.
You need to do this fairly late in the editor creation. In the createPartControl method works:
#Override
public void createPartControl(final Composite parent)
{
super.createPartControl(parent);
getSelectionProvider().addSelectionChangedListener(listener);
}

Hybrid application not showing scroll bar

My WL6.1.0.1 hybrid application have an overflow (with css set to -webkit-overflow-scrolling: touch) which scrolls just fine, but I don't see the scroll bar, neither the android feedback when I hit the bottom of the scroll (that glowing light that android have).
Curiously enough if I access the same application via "Common Resources" using the chrome browser on my android device, both the scroll bar and the feedback shows up.
I added the following code to my main java class on the native side (the one that extends WLDroidGap and have the app name)
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
this.appView.setVerticalScrollBarEnabled(true);
this.appView.setVerticalScrollbarOverlay(true);
}
But it still doesn't work, any ideas?
For the "feedback", you are probably referring to EdgeEffect (when reaching the bottom of the view). If so, it is working for me like this:
public void onWLInitCompleted(Bundle savedInstanceState){
super.loadUrl(getWebMainFilePath());
// Add custom initialization code after this line
this.appView.setOverScrollMode(appView.OVER_SCROLL_ALWAYS);
}
You can set this in the onCreate as well...
For showing the scrollbar, I think you need to use awakenScrollBars() in combination with setVerticalScrollBarEnabled.
That said, I don't know the use case of your app, but typically in an app you would not want a scrollbar unless specifically in a list or something like that (and maybe not even there...).
Additionally, because you are developing a Hybrid app in Worklight and may target additional environments there are alternative solutions instead of delving into native code, such as using iScroll which can take care of much more than just scrolling, but also the "bounce" effect and other things.

SWT/JFace : How to setFont on StatusLine? Windowbuilder broken?

I am a newbie to SWT. There are two problems which have taken up 3 days of resarch, trying, looking and searching. It's a good way to learn about new things, but I'm totally stumped by the following two persistent issues.
Question the first.
public class SWTMN extends ApplicationWindow
{
public final static Display d = new Display() ;
public SWTMN()
{
super(null);
Util.getImageRegistry() ;
addMenuBar();
addStatusLine();
... and so on. Later on ...
'SetStatus("This works fine!") ; // Works fine!!
I want to change the Font of the messages displayed by the statusline - and cannot find a way to do it.
Question the second.
Using a fresh Eclipse Indigo install (updated), creating a fresh (SWT/JFace- support) project, creating a New SWT ApplicationWindow all seems OK. The new file is available in the editor, and compiles - run produces a new, empty window, as it should.
Pressing the "Design" tab cause a modal progress dialogue to appear, with the message "Parsing...", which hangs at about 15% in. The editor windows underneath the progress message are replaced with a general message about a WindowsBuilder internal error - the last line of which is always
ClassCastException cannot cast org.eclipse.swt.shell.Shell to org.eclipse.swt.widget.Widget
(Because the "Parsing ..." progress bar is Application (buggering) modal, Eclipse is now stuffed, and I have to force a quit. Error message offers buttons to re-parse, switch to code which are tempting, and unusable).
Can you help me get Windowbuilder to start-up?
Many thanks for your help!
I'm going to ignore the built-in statusline, as being a solution only for those who are willing to have that exact and limited package of functionality.
It seems odd to me that a GUI-framework so focussed on looking good, would have something so poor as a statusline with a font that does not match the rest of the application.
Go figure.
I'm going to use panel as a custom toolbar, positioning it to the bottom of the frame.
Solution: Found, decided.

jTabbedPane opens different tab on loading

First of all I'm using netbeans as my IDE and I don't know if this is causing it. When I run my program (even if I have build it and run the .jar) I think it selects the tab that was previously selected (before quiting). So if for example I close the app with the third tab selected, it starts up with that selected again. Is there a known solution for this? The selectedIndex property on the jTabbedPane is set to 0. Shouldn't this property be the default onLoad value?
Thx in advance, Jimmy
PS. BTW for some reason it didn't submit my question in Opera (?)
tabbedPaneName.setSelectedIndex(0);
just put that line in the place where the tabbed pane would be loaded
if a button actuion will load the tabbed pane then put the line there
but change tabbedPaneName to YOUR tabbed pane name.
Same problem here with Netbeans 6.8 and JTabbedPane. Neither setSelectedIndex() nor setSelectedComponent() makes a difference. The getSelectedIndex() returns the value previously set, but the pane is not selected correctly.
The reason for this is that the SingleFrameApplication saves it's state and restores the saved state on the next restart. This is done in the code generated by the GUI builder.
You could see that startup() and configureWindow() methods of the SingleFrameApplication are overridden.
Workarounds:
You could override the shutdown() method as well, then modifications to the configuration will not be saved. Note that the original will still be restored, so ensure that the required configuration is saved.
Modifying the startup() method also helps:
MyView myView = new MyView(this);
myView.getFrame().setVisible(true);
myView.getFrame().pack();
The only way it can be set to an index other than zero is if the Java code contains:
tabbedPane.setSelectedIndex(...);
So search the source code for that line and fix it.
Besides using JTabbedPane.setSelectedIndex(), it's also possible to select a tab by calling JTabbedPane.setSelectedComponent(). Have you searched the code for setSelectedComponent() as well?
I had the same problem and found an easy workaround.
In netbean's GUI-builder I set my tabbedpane to not enabled. Later in my program I checked if it was not enabled and in that case called MyTabbedPane.setEnabled(true); and MyTabbedPane.setSelectedIndex(0);
Same problem. Had to go back to NetBeans 7.0.1 to update a JSR 296 application and Java 7 runs it differently than previous versions did so the last tab created was always the one that had focus. Couldn't get anything to change that in the constructor, but finally found just wrapping the same call (setSelectedIndex()) in a call to invokeLater() solves it.
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
tabMain.setSelectedIndex(0);
}
}
);

Drag and drop with an image

I need to create a drag and drop system in swing where an image of the thing being dragged is attached to the cursor during the drag. In theory this is achieveable with
public Icon TransferHandler.getVisualRepresentation(Transferable t)
but there appears to be a long standing bug (here) that means this method is never called. I know I can do it by implementing my own DnD system with DragSource etc., but does anyone know of an easier workround that will get me what I need?
The method TransferHandler.getVisualRepresentation wasn't supported in java 1.4, I'm not sure if or when it was fixed. To test whether it works in a current version you could adapt this example
In the end I used the old style drag-and-drop to implement what I wanted. However I have no reason to think abrightwell's solution wouldn't work just as well - this was just the best way at the time.
You could Try putting the image on a Jlabel (in the draggesture recognizer)and set its bounds, in the droptargetListener dragover method. Alternately, hows about implementing a Mouse listener (I've not tested this latter method).
I have used the "work around" suggested towards the bottom of the bug report you have listed. It worked well enough for me. Granted I was using this with Mac OS X so I have no idea whether Winderz will support it. It would be nice if they would at least fix it to work like they intended and simply document where it will and won't work... oh well. Good Luck.

Categories