how to add a GEF editor to my multiplePage Editor? (eclipse RCP) - eclipse-rcp

I would like to add a GraphicalEditor to a multipage editor. However, when I simply call
addPage(new MyEditor());
inside addPages(), I have an error since. Since my GEF editor extends GraphicalEditor, it cannot extend also FormPage. So, I made it implement IFormPage. But, I still get errors, actually it says that the editor that I'm using for the multipage editor cannot be cast to the one that corresponds to the my graphical editor.
So, finally How can we add a GEF editor to the multipage editor?
Any hint please to solve that?

These are steps that I have done to add gef editor to multipage editor successfully:
Extend org.eclipse.ui.part.EditorPart that have org.eclipse.gef.ui.parts.ScrollingGraphicalViewer as a member.
public class GraphEditorPage extends EditorPart
{
private SPEEditor editor;
private ScrollingGraphicalViewer viewer;
...
}
In method createPartControl you need to layout the editor part, in my case, I did it with a SashForm as parent component, after that, create controls for you graphical viewer on parent component.
In method createPages(), create an GraphEditorPage and add it
private void initGraphPage()
{
graphPage = new GraphEditorPage(this);
addPage(0, graphPage, "Diagram");
}
Hope this help!

Related

How to add Perspective Bar Switcher to pure eclipse 4 rcp application

I have created a pure Eclipse e4 rich client platform application application model. I created multiple perspectives using perspective stack, but I am unable to switch other perspective because there is no default perspective bar or switcher icon present in Eclipse e4. How to implement a perspective switcher in pure Eclipse e4?
EPartService.switchPerspective will do the actual switch, but you will have to design and implement the UI.
You could use a ToolBar in the window Trim Bar with buttons for each perspective. Alternatively a Combo as a Tool Control with a list of the perspectives, it is up to you.
To put a control at the right of a Trim Bar you need to add two Tool Control objects to the trim. Something like:
The first Tool Control is just a spacer to fill the center of the bar.
On the tags tab for the control add the word stretch to tell e4 to stretch this control over as much space as possible:
You will also have to specify a class for the control. This just needs to create an empty Composite to occupy the space. For example:
public class SpacerControl
{
#PostConstruct
public void postConstruct(final Composite parent)
{
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new FillLayout());
}
}
The second Tool Control will contain your Combo control for the perspective switch. Something like:
public class ComboControl
{
#PostConstruct
public void createGui(final Composite parent)
{
Combo combo = new Combo(parent, SWT.READ_ONLY);
... initialize Combo, add listeners, ....
}
}
This should end up looking something like this:

How to get exactly Eclipse Editor kind of Tool Tip in RCP/SWT Table cell

I want to get Exactly eclipse editor kind highly customized tooltip like below-
I used eclipse provided snippets of customized Tooltips but none of them were so highly improvised performance and easy to use.
How to reuse these Tooltips , any example would help.
you just need to extend org.eclipse.jface.window.ToolTip
and override
protected abstract Composite createToolTipContentArea(Event event,
Composite parent);
you can add org.eclipse.swt.browser.Browser and set formatted content and add required controls.

How to use GWT designer with Eclipse GWT plugin?

Sorry but I see no way to use it at all!
If I create GWT project with sample code, then SDK is generating a page with a HTML table where positions for sample TextBox-es and Button are already marked. So, if I open sample file with GWT designer and move button slightly down-right, I will get errors during run.
If I create GWT project without sample code, then GWT designer appears to be unable to open file with empty GUI.
Is there any way to design GUI from scratch or to see GWT designer usage sample?
Thanks
The problem is when you want GWT to create sample code for you, it puts the container parts of layout hard-coded in your projects html file. The generated sample uses RootPanel.get("someId").add(someWidget); to access these containers. When you open designer and move these widgets around, designer generates RootPanel.get("someId").add(someWidget,left,top); which doesn't work with this method.
On another note, when you want to create a class from scratch and open it with designer, you can simply add a reference to RootPanel to get around "this is not a gui class issue" such as :
public class SimpleClass {
RootPanel r = RootPanel.get();
public SimpleClass() {}
}

Creating a JApplet (swing based applet) with netbeans?

I am starting to learn Java a little after long time. And learning Netbeans 7.0.
I just want to make sure I am doing this ok.
I basically need to make an applet, but not having it AWT based, but instead Swing based.
So I need to extend JApplet, not Applet. I understand in swing draws on a Jpanel instead of awt canvas (or Panel). And so I read on a web site that one needs to override PaintComponent() instead of overrriding paint() as the case with awt applet?
I need to make a very simple applet, say with one button, when I click on it, I want to draw a graphics, say a line or circle, and have the output go to an area below the button.
This is what I did
File->New Project
Select Java and from Projects, select "Java Application"
make sure to Un-check the "create Main class", and click Finish
File->New file
Select "Swing GUI Forms" from under the catagories panel
From the "File types", Select Japplet Form,Next and Finish
From the palette, from Swing Controls, select Button and lay it on the from
Now the tricky part. I need an area to draw on, right? So I from palette, I select, from Swing containers, a "Panel", and lay it on the form, resize it as needed. Do, now I have this:
Am I on the right track so far? Now I open the source file, and I see the init() method.
Now is where I need little help. Not sure what the code I need to insert to just draw a line to the JPanel I just added. I know I need to insert it here:
I tried the "insert Code" feature, and select override, but do not see PaintComponent()?
I know how to do it in swt applet, just add a paint(Graphics g) method. But when I do this, the graphics do not draw inside the Jpanel area. Basically, how do I tell it to draw something to a specific JPanel area?
If someone just tell me what code I need to insert there to draw a line or any graphics2D object to display on that JPanel I added below the bottom, that will great.
thanks,
--Nasser
EDIT 1:
Just a clarrification: If I add this function to paint on the Jpanel:
public void paint(Graphics g)
{
super.paint(g);
g.drawString(....);
}
Then the output does show ok, but it over the main Japnel. And can hide the button and any other UI components are there.
I need the paint output to go to a specific Jpanel which I added earlier below the button. To this one
private javax.swing.JPanel jPanel1;
So, my question is, how to draw/paint to the above object and not to the main Jpanel?
EDIT 2:
I tried just to change the JPanel background color, and it is not working. Here is the code.
I also tried JpanelForm instead of JApplet Form. Can one use JFrame form to make an applet? Since that requires a main() it does not seem possible.
import javax.swing.*;
import java.awt.*;
import java.awt.Graphics;
public class NewJApplet extends javax.swing.JApplet
{
/** Initializes the applet NewJApplet */
public void init()
{
jPanel1 = new JPanel();
try
{
java.awt.EventQueue.invokeAndWait(new Runnable()
{
public void run()
{
initComponents();
}
});
} catch (Exception ex)
{
ex.printStackTrace();
}
}
private void initComponents() {...}
//--------- ADDED THIS
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
Rectangle rect=new Rectangle(4,4);
jPanel1.setBackground(Color.RED);
}
//---------------
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
NetBeans "does" support JApplet. After creating a new project, rt-click on the project's package in "projects" pane which is to the left of your coding area and choose New -> JApplet
netbeans does not support making JApplets, only applets. Use standard text editor to design the JApplet interface then compile the source code using javac.
I went through the same thing just now, you just need to take the package name out from the file and just compile it. You will get a message in netbeans that the applet is not initialized which is ok, just go to the source folder where .class files are stored you will find multiple NewJApplet.class files, You will see some with a $ sign in them too.
Copy all the .class files put it together with the html file and that is it. View your JApplet created using the form on the browser. Makes creating anything with java so much fun.

Refreshing the workbench

HI,
I am facing some problem.. I want to hide the menu when eclipse workbench starts.
But the problem is menu is not hiding when the eclipse workbench starts. It is hiding only
when some refresh is happened. for example: when I change the default perspective to some other perspective, I am getting the desired out put. That means menu is hiding.
But when the eclipse workbench is loaded it is not hiding the menu. Below is my code.
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
try {
IWorkbenchWindow window = Workbench.getInstance().getActiveWorkbenchWindow()
if(window instanceof WorkbenchWindow) {
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
IContributionItem[] items = menuManager.getItems();
for(IContributionItem item:items){
System.out.println("item.getId()::: "+item.getId());
menuManager.remove("org.eclipse.ui.run");
menuManager.remove("help");
menuManager.remove("project");
}
}
}`
}
};
Given that you are looking to hide some features, I don't think that this is the best approach. (Not I am using the term feature here in the colloquial way, not as an Eclipse feature.
I would recommend one of two avenues:
Perspectives: See the extension point org.eclipse.ui.perspectives. This allows you to create a new perspective like the debug perspective or the Java perspective. Using a perspective, you can select exactly what menu items and views are shown and which ones are hidden.
Capabilities (aka activites): See the extension point org.eclipse.ui.activities. This allows you to have some fairly fine-grained control over what features are available in the workspace. See more info here: http://wiki.eclipse.org/Galileo_Capabilities
Put Your code in org.eclipse.ui.startup extention point. Make a Startup class after implementing the interface IStartup. For Details follow this link:-
Eclipse plugin : disable/enable dynamically an action from main menubar