How to create view via fragment that is linked to applicatio model eclipse plugin - eclipse

Using application.e4xmi, I want to create view via fragments using this application model. Could you please tell me the step by step procedure.
what i have tried is, i have created one fragment in the one plugin application. in that i have given application id after that i have created part stack and after that created part. Here i have given class URI is my view class(path of view class in the viewplugin project). But without that view plugin in the runconfigurations, i am unable to see view part.

As far as I understand your question, you wish to have a plugin containing a model fragment which contributes to an application model located in another plugin, and the problem is that a (View-)Part you tried to contribute that way doesn't show in the application window. I hope I didn't get you wrong there and I will assume that the error is not just that the plugin with the model fragment is not included in the run configurations... (?)
You can find a useful tutorial in Lars Vogel's webpages. However, as the various requirements may be confusing, I will summarize the process for potential future readers.
TL;DR:
You might have set a wrong Element ID and/or Featurename for your Part.
Your question implies that you maybe tried to implement a Part model element as a ViewPart, when in E4, there is no longer any interface for a (View) Part to implement, so maybe try creating the Part controls in a #PostConstruct-annotated method instead.
Another possible reason for your contributed Part not showing up is the plugin providing the model fragment not having the correct settings for the bundle options SymbolicName and/or ActivationPolicy ('Plug-in is singleton' and 'Activate when class is loaded').
Application
In order to have an application model to contribute to, we first need an Eclipse4 application project. Create one by selecting File -> New -> Other from the Eclipse main menu. Choose the wizard Eclipse 4 Application Project in the Eclipse 4 category. Name your project as you wish, choose Equinox as OSGI framework, and check the Generate an Activator... option. The newly created project will contain a file Application.e4xmi (your application model) and a *.product file (product definition). Open the latter in and make sure org.eclipse.e4.ui.workbench.swt.E4Application is set as Application in the Overview tab.
Open Application.e4xmi and append a Part Stack somewhere in the model tree, as you probably have already done anyways.
Model fragment
Create a new plugin for the model fragment. Letting it have an Activator class won't harm. It is important, however, that the options Activate this plug-in when one of its classes is loaded and This plug-in is a singleton are both checked in the Overview tab of its plugin.xml editor. Next, create a model fragment with New -> Other... -> Eclipse 4 -> Model -> New Model Fragment in the plugin's Package Explorer context menu. The wizard will automatically create an extension of org.bbaw.bts.ui.pdr.fragment specifying your model fragment file. The plugin's dependencies should include:
org.eclipse.swt
org.eclipse.jface
org.eclipse.e4.core.di
org.eclipse.e4.ui.workbench
javax.inject
org.eclipse.e4.ui.di
Open the model fragment file (fragment.e4xmi by default) and attach a Model Fragment to the Model Fragments node. Your new Model Fragment element needs to specify both an Element ID and a Featurename in order to correctly address the Application Model's element that you want to contribute to. Thus, copy the ID of the Part Stack previously created in the Application Model into the Element ID field of the Model Fragment you've just created. In the Featurename field, type children, as this is the Part stack's attribute we want to contribute to. Then, append a Part to the Model Fragment element and specify the Class URI of the Part's implementation. This class is basically a POJO, no implementation of ViewPart is necessary! It creates its GUI in a method annotated with the #PostConstruct annotation, e.g.
#PostConstruct
public final void createComposite(final Composite parent)
That should be it. When running the application project's product, the Part should appear like expected (given the plugin containing that Part is included in the run configuration...).

Related

How to extend IDocumentListener in eclipse for creating plugin?

I am trying to create a plugin which monitors the change in a document.
I am interested in adding a marker in the text editor when the document is changed.
I observed that for the class - IDocumentListener the method documentChanged is getting called whenever there is a change.
However, I am unable to implement this as plugin as this interface does not have an extension point.
Can you help me with extending IDocumentListener ?
It's instructive to look at an existing open-source plugin to see how it does a similar task. Let's look at Bracketeer as an example.
The starting point is a class that implements org.eclipse.core.runtime.Plugin. For plugins that have a UI, it's useful to implement org.eclipse.ui.plugin.AbstractUIPlugin which provides additional functionality. This class is commonly called the "activator", and indeed in Bracketeer it's called Activator. It's registered as the plugin's activator class in the MANIFEST.MF file using a line like:
Bundle-Activator: com.chookapp.org.bracketeer.Activator
The Activator class overrides Plugin.start(), which will be called by the runtime when the plugin is loaded. The overridden start() method sets up a part listener.
The part listener is a class that implements the IPartListener2 interface. In Bracketeer, it's called PartListener. On setup, it calls PlatformUI.getWorkbench() to get a hold of the IWorkbench, and IWorkbench.getWorkbenchWindows() to get a list of currently open windows (at the time the plugin starts). It then registers itself with each window via IWorkbenchWindow.getPartService().addPartListener().
In addition, to handle new windows being opened after the plugin is loaded, PartListener also implements IWindowListener, and registers itself as a window listener via IWorkbench.addWindowListener(). This allows the PartListener to handle new windows opening by overriding IWindowListener.windowOpened(), and register itself as a part listener for the new windows.
As a part listener, PartListener overrides IPartListener2.partActivated() and partOpened() to handle workbench parts (which include editors) being opened or activated. In those methods, it checks whether the part is an IEditorPart; if so, it gets a hold of the editor part's document (see PartListener.getPartDocument()), which is an IDocument.
Finally, having an IDocument, it can register any IDocumentListener it wants via IDocument.addDocumentListener(IDocumentListener).
(There are some details I'm glossing over, such as manually calling partActivated() for every workbench part that's already open at the time the plugin is started. See the Bracketeer code for the full details.)
All of these are public APIs, and none of this requires any extension point to be implemented.

How to distinguish wizards in Eclipse RCP?

We have an Eclipse IDE application on 3.x that uses various newWizards to allow the user to create different files. Although these files differ slightly contentwise, the structure of the wizards is quite similar.
Thus, a sound object-oriented approach would be to instantiate different wizards from the same class and initialize them with different data.
Problem:
To decide what wizard needs which data we need a way to distinguish the different already instantiated wizards (e.g during the call to the init method of the wizard).
Is there any way to do so? It would e.g. help if somebody knows a way to get the wizard's id defined in the extension point from within the instantiated wizard.
If your wizard implements IExecutableExtension, it will be passed the configuration element that represents the extension for which it is created.
You can also use extension factories in that you specify a type that implements IExecutableExtensionFactory.
The interface allows you to control how the instances provided to extension-points (wizards in your case) are created.
Extension example:
<extension point="org.eclipse.ui.wizards">
<newWizard
name="..."
class="com.example.WizardFactory">
</newWizard>
Note that the extension factory may also implement IExecutableExtension to gain access to extension attributes before creating the extension's executable class.

ATG browser components is not available

I want to create new companent in ATG. And if I forward to Browser Companent page, then I have 404 error. How I can fix this?
I assume that you have created a new component by creating a .properties file. The things to look for are
Is the file in an appropriate config layer? i.e. is it in a location on the configpath, such as the config directory of a module, or the localconfig directory of a server, where the application expects to look for .properties files?
Is the file a valid .properties file and properly formatted?
Is the class mentioned in the $class property correct, valid and fully qualified (package name and class name)
Has the named class been compiled successfully?
Is the named class available on the classpath? i.e. is it in the classes.jar of a module or in the classes directory (if that is how the module's class path has been defined?
Is the class a valid JavaBean - particularly, does it have a no-argument constructor?
Have you compiled, built and assembled your ATG application since creating this new component?
Have you restarted your ATG application since creating this new component?
Assuming this is all correct and yet you still cannot see your component, the next step is to troubleshoot why it is not visible.
Is the path to your component you are using in the dyn/admin component browser correct?
If the path is correct, and you still see an error in the browser, then take a look at the server logs (for around the time you first tried to access the component) - you might see an error or a sequence of errors telling you why the server could not instantiate the component
Can you go to the containing folder and see if the component is listed there - though it is OK if you cannot because it may not have been started if nothing is referencing it
Can you see your component in the ACC. Start the ACC, and go to View Components by Path and navigate to were you think your component should be. Can you see it there? If so, it means that your properties file is OK.
In the ACC, When you click on the puzzle-piece icon that represents your component, does it show it as being an instance of your class or as an instance of Object. If Object, it means that it cannot determine the class of the component
In the ACC, double-click the component and try to start it. Keep looking at the server logs as you do so
This should help you get to the bottom of things.

How do I get a view part instance in an Eclipse e4 application?

I'm trying to get the instance of a view part in an Eclipse e4 application but I can't find the PlatformUI class. Has the name changed since Eclipse 3 or is it located in a different package?
When looking at Eclipse e4 Parts:
bugs like 371405 can be instructive:
org.eclipse.ui.presentations
This API no longer works in 4.2, and we never intend to make it work.
It is incompatible with the pluggable rendering story in 4.2. Decisions that could once be made by the presentation extensions are now up to the renderer.
Affected API that needs deprecation:
Entire API package: org.eclipse.ui.presentations
Extension point:org.eclipse.ui.presentationFactories
org.eclipse.ui.IWorkbenchPreferenceConstants#PRESENTATION_FACTORY_ID
org.eclipse.ui.IWorkbenchWindowConfigurer#getPresentationFactory
org.eclipse.ui.IWorkbenchWindowConfigurer#setPresentationFactory
The rest of the Tutorial explains how to declare "parts" (editors or views)
The OP August Karlstrom mentions:
This used to work:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("‌​some view");
Using a singleton like PlatformUI is a bad practice and one of the reason of the introduction, in e4, of Context. See this presentation on Context.
Paul Webster (IBM Eclipse Platform team member) comments:
In Eclipse4 you would use org.eclipse.e4.ui.workbench.modeling.EPartService.findPart(String) to find an MPart by ID.
The MPart contains the injected part in its object property.
As the page Workbench_Services details:
In e4, the notion of a workbench page will not be present.
The part service API will essentially be a merge of the existing 3.x IPartService and WorkbenchPage interfaces.
Note that this isn't ideal, as bug 372488 illustrates (following this thread):
An MPart for an MPartDescriptor is created with EPartService.createPart(descriptor_id), where descriptor_id is the identifier of the MPartDescriptor.
This part can be found again with EPartService.findPart(descriptor_id) -- if there is only one.
The problem is, that one may need do create more than one MPart for one MPartDescriptor.
An editor may be one example: one may want to edit different instances of one and the same kind.
The creation of more than one MPart for a given MPartDescriptor is possible, but there is no convenient method to find these parts.
EPartService.findPart(descriptor_id) will return the first MPart created for a particular MPartDescriptor, even if there is more than one.
So there are three problems, for a given MPartDescriptor:
EPartService.findPart(id) does not tell that there is more than one MPart.
There is no convenient way to get all MParts for this descriptor.
There is no API-way to get the particular MPart for given descriptor and "content" or "reference".
Currently the way to go is using EPartService.getParts() which unfortunately
returns all MParts, not only those corresponding to one particular
MPartDescriptor.
Then one would need to check, whether there is one MPart for the particular MPartDescriptor having a particular "content".
So something is missing that will find an MPart for a given MPartDescriptor
with particular "content" or "reference".
Just have the same question. After found this thread and tried with:
MPart mPart = epartService.findPart("MyPart");
MyPart myPart = (MyPart)mPart.getObject();
then I got my view part.

Netbeans: using GUI Builder on regular Java class file

I'm using Netbeans. When I create a Java class, I sometimes want to change it to be a GUI component so that I can visually edit it using the GUI Builder.
What is the necessary step to transform a regular Java class to a GUI component so that Netbeans would recognize it and allow me to use GUI Builder ? (i.e. switch between Source and Design)
NetBeans' Gui builder, Matisse, works off a .form xml file located adjacent to the source file. Matisse creates and maintains the .form file and the code generator creates/updates methods in the java source to reflect changes to the form.
Unfortunately, there is no support in NetBeans for free-form GUI construction.
The closest I've seen is FormGenerator. It's a contributed NetBeans module that adds a right click action to .java files that will attempt to generate a .form file from the .java source. It's very limited, but it's better than nothing. It works best if you've followed the coding style employed by Matisse.
http://netbeans.org/projects/contrib/downloads/download/Readme.txt
http://netbeans.org/projects/contrib/downloads/download/FormGeneratorModule.zip
To add a class to the Palette, all that's needed is for your class to conform to the Java Beans model. That is, your class must:
be serializable
have a public, no-argument constructor.
All fields that have getter and setter methods that are named properly, i.e.:
int count
int getCount()
void setCount(int c)
should by default be recognized as a property.
For a finer control of what properties should and should not be exposed to the GUI Builder, you can associate your class with an implementation of the BeanInfo interface. See this Sun tutorial for more details.
However, NetBeans has several tools to help you in designing a custom bean. You can create new beans using the built-in templates available in the new file dialog, under the "JavaBeans Objects" folder.
This tutorial will guide you through creating an Image Bean.
What you could do is create one from scratch, design it as you wish, and then look at the generated code to understand how you can modify your existing class.
Try to use properties (Java bean!) for properties which should be changed from the ui designer and look here for more info.