Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[gef-dev] Source Code and Plugin...


Hello  PBrunel
 
Here is the source code for my example...
 
 

/++++++++++++++++Model  PART+++++++++++++++++++++++++++

public class HelloModel {
 private String text = "Hello World";

 public String getText() {
  return text;
 }

 public void setText(String text) {
  this.text = text;
 }

}

 

/++++++++++++++++Edit PART+++++++++++++++++++++++++++

 

public class HelloEditPart extends AbstractGraphicalEditPart {


 protected IFigure createFigure() {
  HelloModel model = (HelloModel) getModel();

  Label label = new Label();
  label.setText(model.getText());
  
  return label;
 }

 protected void createEditPolicies() {

 }
}

/++++++++++++++++Edit Factory+++++++++++++++++++++++++++

public class MyEditPartFactory implements EditPartFactory {

 public EditPart createEditPart(EditPart context, Object model) {
  EditPart part = null;

  if (model instanceof HelloModel)
   part = new HelloEditPart();

  part.setModel(model); 

  return part;
 }

}

/++++++++++++++++View Part+++++++++++++++++++++++++++

public class HelloGEFView extends ViewPart{
 
 public HelloGEFView(){
  
 }
 public void createPartControl(Composite parent){
  
  Label l=new Label(parent,SWT.WRAP);
  l.setText("GEF Worked....");
  
 }
 
 public void setFocus(){ }
}

 

/++++++++++++++++HelloWorldEditor Part+++++++++++++++++++++++++++

public class

?xml version="1.0" encoding="UTF-8"?>

<?eclipse version="3.0"?>

 

<plugin>

 

<extension

 

point="org.eclipse.ui.actionSets">

 

<actionSet

 

label="Sample Action Set"

 

visible="true"

 

id="test.actionSet">

 

<menu

 

label="Sample &amp;Menu"

 

id="sampleMenu">

 

<separator

 

name="sampleGroup">

 

</separator>

 

</menu>

 

<action

 

label="&amp;Sample Action"

 

icon="icons/sample.gif"

 

class="test.actions.SampleAction"

 

tooltip="Hello, Eclipse world"

 

menubarPath="sampleMenu/sampleGroup"

 

toolbarPath="sampleGroup"

 

id="test.actions.SampleAction">

 

</action>

 

</actionSet>

 

</extension>

 

</plugin>

 extends GraphicalEditor {

 public final static String ID = HelloWorldEditor.class.getName();

 public HelloWorldEditor() {
  setEditDomain(new DefaultEditDomain(this));
 }

 protected void initializeGraphicalViewer() {
  GraphicalViewer viewer = getGraphicalViewer();
  viewer.setContents(new HelloModel());
 }

 public void doSave(IProgressMonitor monitor) {

 }

  public void doSaveAs() {

 }

 public void gotoMarker(IMarker marker) {

 }

 public boolean isDirty() {
  return false;
 }

 public boolean isSaveAsAllowed() {
  return false;
 }

 protected void configureGraphicalViewer() {
  super.configureGraphicalViewer();
  GraphicalViewer viewer = getGraphicalViewer();
  viewer.setEditPartFactory(new MyEditPartFactory());

 }

}

 

 /***************************** Plugin Code *****************************************/

 

?xml version="1.0" encoding="UTF-8"?>

<?eclipse version="3.0"?>

 

<plugin>

 

<extension

 

point="org.eclipse.ui.actionSets">

 

<actionSet

 

label="Sample Action Set"

 

visible="true"

 

id="gef.example.helloworld.HelloWorldEditor"

 

<action

label="&amp;Sample Action"

icon="icons/sample.gif"

class="gef.example.helloworld.HelloWorldEditor"

tooltip="Hello, Eclipse world"

menubarPath="sampleMenu/sampleGroup"

toolbarPath="sampleGroup"

id="gef.example.helloworld.HelloWorldEditor">

</action>

</actionSet>

</extension>

</plugin>

 

 
/**************************************************************************/
 
I still have once question ?? Can i use GEF AND EMF FOR developing a small GUI editor plus code generator with these Frameworks ?? I think so yes we can or ??
 
thank u  

--
Saqib Nasir

Back to the top