I am doing a project using GEF. I need to open a popup window when double click the model in the canvas.
I create a SWT window and let GEF to open it. But the problem is it casue an exception:
Exception in thread "Thread-5" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Invalid thread access)
when running following code.
while(!shell.isDisposed()){
**if(!display.readAndDispatch()){**
display.sleep();
}
}
What i did in my project is create the SWT window, then make a thread to run it, and call the thread in my model's editpart like this:
public void performRequest(Request req)
{
swtthread aa = new swtthread();
aa.start();
}
Do possible a GEF can use SWT window as a popup window or is there any other way to do this?
Thank you
Sound strange, but I have no experiences with GEF though. According to this SWT FAQ you call UI method from non-UI thread, try to wrap the code with
display.syncExec(
new Runnable() {
public void run(){
... // your code
}
});
You can also use asyncExec, depending on your needs..
Related
I'm working for a short time on the libraries of eclipse 4.x someone could tell me how can I open a view through from the context menu? Thank you in advance.
To show a part anywhere you should define a command in the application model and a handler for the command. To show a part in the handler use:
#Execute
public void execute(EPartService partService)
{
MPart mpart = partService.showPart(part id, PartState.ACTIVATE);
}
In the application Part definition for your part add a Popup Menu to the Menus section. In the popup menu define a HandledMenuItem for your command.
To register the popup menu as the context menu for a control (tree, table etc) use:
#Inject
private EMenuService;
...
menuService.registerContextMenu(control, menu id);
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!
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
I am working on an Eclipse based RCP. We have a need to prevent one of the opened editors from being closed by the user.
The desired behavior is:
the user clicks the X in the editor window or "CTRL+W"
a dialog pops up saying: "If you close this editor, your activity will stop. Do you want to?"
if they click yes, it closes, if no, it stays open.
Oh yeah, and is this even possible?
Thanks,
gk
You could use a org.eclipse.ui.ISaveablePart2, more specifically the method promptToSaveOnClose().
However, as said in this thread,
it will only be shown if the editor is dirty at the time it is closed.
See an example in this SaveableHelper.java source file.
See also the article Prevent that a RCP Editor is closed, which explains how this method works:
You can also cancel the saving in
#Override
public void doSave(IProgressMonitor monitor) {
by calling
monitor.setCanceled(true);
In the EditorPart implementation
Not directly related but I was looking for a way to prevent an Editor to be closed and found this little hack, hope it could help.
page.addPartListener(new IPartListener2() {
// [...]
#Override
public void partClosed(IWorkbenchPartReference partRef) {
try {
page.openEditor(input, id);
} catch (PartInitException e) {
e.printStackTrace();
}
}
});
I have a plug-in to an Eclipse RCP application that has a view. After an event occurs in the RCP application, the plug-in is instantiated, its methods are called to populate the plug-in's model, but I cannot find how to make the view appear without going to the "Show View..." menu.
I would think that there would be something in the workbench singleton that could handle this, but I have not found out how anywhere.
You are probably looking for this:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("viewId");
If called from handler of a command
HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView(viewId);
would be better, as I know.
I found the need to bring the view to the front after it had been opened and pushed to the background. The activate method does the trick.
PlatformUI.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.activate(workbenchPartToActivate);
NOTE: The workbenchPartToActivate is an instance of IWorkbenchPart.
In e4, the EPartService is responsible for opening Parts. This can also be used to open e3 ViewParts. Instantiate the following class through your IEclipseContext, call the openPart-Method, and you should see the Eclipse internal browser view.
public class Opener {
#Inject
EPartService partService;
public void openPart() {
MPart part = partService.createPart("org.eclipse.ui.browser.view");
part.setLabel("Browser");
partService.showPart(part, PartState.ACTIVATE);
}
}
Here you can find an example of how this works together with your Application.e4xmi.