Trying to create simple GEF - eclipse-rcp

i am trying to create simple automation tool for testing.I have followed a simple tutorials
on net and created a RCP with view on eclipse. now i have tried to include simple GEF
component on the view it throws me error saying " Could not create the view: Plug-in "GEFTutorial" was unable to instantiate class "geftutorial.View"."
here is my source code
particularly when i uncomment creation of
private ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
private RootEditPart rootEditPart = new ScalableFreeformRootEditPart();
private EditPartFactory editPartFactory = new SimpleGEFEditPartFactory();
all the above statements on the view.my view appears back
here is my source code for view.java
package geftutorial;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.gef.*;
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer;
public class View extends ViewPart {
public static final String ID = "GEFTutorial.view";
//Use a standard Viewer for the Draw2d canvas
private ScrollingGraphicalViewer viewer = new ScrollingGraphicalViewer();
//Use standard RootEditPart as holder for all other edit parts
private RootEditPart rootEditPart = new ScalableFreeformRootEditPart();
//Custom made EditPartFactory, will automatically be called to create
//edit
// parts for model elements
private EditPartFactory editPartFactory = new SimpleGEFEditPartFactory();
//The model
private SuperWidget model;
//private TableViewer viewer;
/**
* The content provider class is responsible for providing objects to the
* view. It can wrap existing objects in adapters or simply return objects
* as-is. These objects may be sensitive to the current input of the view,
* or ignore it and always show the same content (like Task List, for
* example).
*/
class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object parent) {
if (parent instanceof Object[]) {
return (Object[]) parent;
}
return new Object[0];
}
}
class ViewLabelProvider extends LabelProvider implements
ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
}
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().getSharedImages().getImage(
ISharedImages.IMG_OBJ_ELEMENT);
}
}
/**
* This is a callback that will allow us to create the viewer and initialize
* it.
*/
public void createPartControl(Composite parent) {
/*viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
// Provide the input to the ContentProvider
viewer.setInput(new String[] {"One", "Two", "Three"});
*/
//Create a dummy model
model = new SuperWidget("Model");
model.createDummyModel();
//Initialize the viewer, 'parent' is the
// enclosing RCP windowframe
viewer.createControl(parent);
viewer.setRootEditPart(rootEditPart);
viewer.setEditPartFactory(editPartFactory);
//Inject the model into the viewer, the viewer will
// traverse the model automatically
viewer.setContents(model);
//Set the view's background to white
viewer.getControl().setBackground(new Color(null, 255,255,255));
}
/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
viewer.getControl().setFocus();
}
}
Can someone give me a clue about this? i am new to RCP and GEF :(

I'm also just learning GEF, but from what I have seen gef editors are not ViewPart (views) but editors, extending EditPart.
Check my ongoing GEF tutorial here. Hope it helps.
You can also access other GEF tutorial from the eclipse website.

Related

Passing Data Between Fragments from a BaseAdapter override class

Ik im probably not going about this the best way , but I have no idea how to go about this the right way given my current setup . Pretty much I have a fragment tabhost that has just about all my content including a newsfeed, from the newsfeed users can click another users picture to open their profile. Up until now I was taking the easy way out and just using a intent which opened a whole new instance of the tabhost and all the fragments, i sent the profile id over via a intent extra and my problem was solved, but ive since learned this isnt a great solution . So ive been trying to fix up my app by taking the advice on this thread:
Communication between Fragments
my problem is bc my onClick listeners for the profile images is in my LazyAdapter class which extends BaseAdapter, whats the best way to switch out the fragments and pass over the proper profile id to the new fragment given my situation?
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class LazyAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.list_row, null);
TextView name = (TextView)vi.findViewById(R.id.name); // title
TextView message = (TextView)vi.findViewById(R.id.message); // artist name
TextView created = (TextView)vi.findViewById(R.id.created); // duration
SmartImageView thumb_image = (SmartImageView) vi.findViewById(R.id.list_image);
HashMap<String, String> update = new HashMap<String, String>();
update = data.get(position);
// Setting all values in listview
name.setText(update.get("name"));
message.setText(update.get("message"));
created.setText(update.get("created"));
thumb_image.setImageUrl(update.get("thumb_img"));
name.setOnClickListener(new myOnClickListener(position));
thumb_image.setOnClickListener(new myOnClickListener(position));
return vi;
}
public class myOnClickListener implements OnClickListener{
private int position;
private String clicked_uid;
public myOnClickListener(int position){
this.position=position;
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
HashMap<String, String> update = new HashMap<String, String>();
update = data.get(position);
Log.i("Update Position:", update.toString());
clicked_uid=update.get("uid");
Log.d("Clicked UID:", clicked_uid+"");
Intent i = new Intent(activity.getApplicationContext() , TabHostFragmentActivity.class);
i.putExtra("profile_uid", clicked_uid);
activity.startActivity(i);
activity.finish();
}
}
}

auto refresh eclipse view

i have created a sample view in eclipse using the following code.i want the view to be
automatically refereshed.the part of code in quotes "" gives refresh option but it is done
manually.can anyone help me know how it can be done automatically
public class SampleView extends ViewPart {
public static final String ID = "tab.views.SampleView";
private TableViewer viewer;
class ViewContentProvider implements IStructuredContentProvider {
public void inputChanged(Viewer v, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object parent) {
return new String[] { "Status of your hudson build is: " +hudson.d};
}
}
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
public String getColumnText(Object obj, int index) {
return getText(obj);
}
public Image getColumnImage(Object obj, int index) {
return getImage(obj);
}
public Image getImage(Object obj) {
return PlatformUI.getWorkbench().
getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD);
}
}
public SampleView() {
}
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.setContentProvider(new ViewContentProvider());
viewer.setLabelProvider(new ViewLabelProvider());
viewer.setInput(getViewSite());
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "Tab.viewer");
hookContextMenu();
}
" private void hookContextMenu() {
MenuManager menuMgr = new MenuManager("#PopupMenu");
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
Action refresh =new Action() {
public void run() {
// initialize();
viewer.refresh();
}
};
refresh.setText("Refresh");
menuMgr.add(refresh);
}"
public void setFocus() {
viewer.getControl().setFocus();
}
}
It is only possible to refresh the tree contents automatically, if you fill it using JFace Data Binding, that would not work with remote build results.
I recommend either using a model with notification support: when the model changes, its listeners are notified. Then your view could listen for these notifications and refresh itself.
If for some reason this is not possible, you have to poll your models manually. For that I recommend creating a Job that is executed in the background automatically (its last step is to reschedule itself some times later), that checks whether the model changed and refreshes the view.

GWT cell widgets with overlay types issues

I have taken the Cell Table example from google developer's guide and made the following changes:
Use overlays instead of Java POJOs
Use a EditTextCell to edit one column
For my surprise, when running the code the Cell Table is adding an extra property to the overlay objects pushed into it. They should look like:
{"name":"John", "address":"123 Fourth Road"}
{"name":"Mary", "address":"222 Lancer Lane"}
But instead they look like:
{"name":"John", "address":"123 Fourth Road", "$H":1}
{"name":"Mary", "address":"222 Lancer Lane", "$H":2}
Here is the modified code that demonstrates the issue:
import java.util.Arrays;
import java.util.List;
import com.google.gwt.cell.client.EditTextCell;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Overlay implements EntryPoint {
private static class Contact extends JavaScriptObject {
protected Contact() {}
public static native Contact create(String name, String address) /*-{
return {"name" : name , "address" : address};
}-*/;
public final native String getName() /*-{
return this["name"];
}-*/;
public final native void setName(String name) /*-{
this["name"] = name;
}-*/;
public final native String getAddress() /*-{
return this["address"];
}-*/;
public final native void setAddress(String address) /*-{
this["address"] = address;
}-*/;
}
private static List<Contact> CONTACTS = Arrays.asList(
Contact.create("John", "123 Fourth Road"),
Contact.create("Mary", "222 Lancer Lane"));
/**
* This is the entry point method.
*/
public void onModuleLoad() {
CellTable<Contact> table = new CellTable<Contact>();
// Create name column.
Column<Contact, String> nameColumn = new Column<Contact, String>(new EditTextCell()) {
public String getValue(Contact object) {
return object.getName();
}
};
// Create address column.
TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
public String getValue(Contact contact) {
return contact.getAddress();
}
};
// Add the columns.
table.addColumn(nameColumn, "Name");
table.addColumn(addressColumn, "Address");
table.setRowCount(CONTACTS.size(), true);
// Push the data into the widget.
printList();
table.setRowData(0, CONTACTS);
printList();
RootPanel.get().add(table);
}
private void printList() {
for(Contact contact : CONTACTS) {
GWT.log(new JSONObject(contact).toString());
}
}
}
I have checked that it is the editable column the one that causes the issue. If I remove it the table does not modify my overlays.
Anyway, this is a very weird behaviour. I don't feel it is safe to work with overlays if your widgets can add them unexpected properties.
Has anyone encountered this issue before or is this behaviour documented anywhere? Any hints to solve it?
Thanks a lot
The correct answer to this issue was posted in the GWT development forum (link):
The $H property comes from the
implementation of
JavaScriptObject#hashCode() (in
com.google.gwt.cire.client.impl.Impl#getHashCode(Object)).
In your case, this is due to
AbstractEditableCell maintaining a map
of value keys to their "view data",
and your use (I guess) of the default
ProvidesKey implementation
(SimpleProvidesKey) which directly
returns the item.
So, when rendering, the EditTextCell
calls getViewData, which looks up the
key in the map (and thus needs the
hashcode of the key, hence the call to
hashCode), and the key is your JSO
(hence the new $H property).
I believe that giving a ProvidesKey
implementation (in you case, returning
the name property for instance) to the
Celltable would solve your issue.
I doubt that CellTable can sneakily edit your JSONs. Check those overlays in Firebug/Chrome_Developer_Tools/... if they ok then most likely bug is in this line:
GWT.log(new JSONObject(contact).toString());
There are atleast two issues for JSONObject.toString: Passing List to/from JSNI works in web mode but fails in hosted mode & toString() and JSNI.
In second issue there is comment according to which you can try this:
GWT.log( (String) new JSONObject(contact) );

accessing array with object

hi i have two classes in android and in one class i have write an array and i want to access it in the main class but the error is give me that "force closed" here is my code
package com.semanticnotion.DAO;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class DAO extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WordsDAO DAO = new WordsDAO(new String[] "Arte","Arquitectura","Familia","Moda","Cotilleos","Cine","Libros","Historia","Pintura","Musica","Tendencies","Modernimso","Pop art","Masteialismo","realities","filosofia","moda","fotografia","religion"});
Button next = (Button) findViewById(R.id.Button01);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), WordsDAO.class);
startActivity(myIntent);
}
});
}
}
and the second class code is
package com.semanticnotion.DAO;
public class WordsDAO
{
String[] words = new String[] "Arte","Arquitectura","Familia","Moda","Cotilleos","Cine","Libros","Historia","Pintura","Musica","Tendencies","Modernimso","Pop art","Masteialismo","realities","filosofia","moda","fotografia","religion"};
public WordsDAO(String[] words )
{
this.words=words;
}
}
please any one tell what well be the error in this code thaks
First of all: the constructor in your second class would not be used. The way to pass parameters to another activity is to use Intent.putExtra in the code calling the other activity and in your other activity use
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
String value = extras.getString("keyName");
}
to get the data in onCreate.
That said, I guess the problem arises from your second class not providing an explicit parameterless constructor.

How do I get notified whenever a new editor is opened in Eclipse?

I have a view which would like to be notified about all the currently opened editors. Where can I add a listener to achieve this?
I was expecting WorkbenchPage or EditorManager to have some appropriate listener registry, but I couldn't find it.
Does your view uses a org.eclipse.ui.IPartListener2 ?
That is what is using this EditorListener, whose job is to react, for a given view, to Editor events (including open and close)
public class EditorListener implements ISelectionListener, IFileBufferListener,
IPartListener2 {
protected BytecodeOutlineView view;
EditorListener(BytecodeOutlineView view){
this.view = view;
}
[...]
/**
* #see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
*/
public void partOpened(IWorkbenchPartReference partRef) {
view.handlePartVisible(partRef.getPart(false));
}
Now if your ViewPart directly implements an IPartListener2, it can register itself to the various Editors, like this BytecodeReferenceView
public class BytecodeReferenceView extends ViewPart implements IPartListener2, ISelectionListener {
[...]
public void createPartControl(Composite parent) {
browser = new Browser(parent, SWT.BORDER);
browser.setText(BytecodeOutlinePlugin.getResourceString(NLS_PREFIX
+ "empty.selection.text"));
final IWorkbenchWindow workbenchWindow = getSite().getWorkbenchWindow();
workbenchWindow.getPartService().addPartListener(this);
[...]
I think you're on the right track. You need to listen to the IWorkbenchPage IPartService events:
page.addPartListener(new IPartListener() {
partOpened(IWorkbenchPart part) {
...
}
...
});