Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] hyperlink using SWT

㱈呍䰠硭汮猺敘捬慩浥爽≨瑴瀺⼯睷眮數捬慩浥爮捯⹵欢⁸浬湳㩭獸獬㴢畲渺獣桥浡猭浩捲潳潦琭捯洺硳汴∠硭汮猺數挽≨瑴瀺⼯睷眮數捬慩浥爮捯⹵欯牴昢㸊㱈䕁䐾਼䵅呁⁨瑴瀭敱畩瘽≃潮瑥湴ⵔ祰攢⁣潮瑥湴㴢瑥硴⽨瑭氻⁣桡牳整㵕呆ⴱ㘢㸊ਊ㱍䕔䄠桴瑰ⵥ煵楶㵃潮瑥湴ⵔ祰攠捯湴敮琽≴數琯桴浬㬠捨慲獥琽楳漭㠸㔹ⴱ∾਼䵅呁⁣潮瑥湴㴢䵓䡔䵌‶⸰〮㈹〰⸲㜲㈢慭攽䝅久剁呏刾਼協奌䔾䁰慧攠卥捴楯渱⁻獩穥㨠㠮㕩渠ㄱ⸰楮㬠浡牧楮㨠ㄮど渠ㄮ㈵楮‱⸰楮‱⸲㕩渻⁽੐⹍獯乯牭慬⁻ਉ䙏乔ⵓ䥚䔺‱㉰琻⁍䅒䝉为‰楮‰楮‰灴㬠䙏乔ⵆ䅍䥌夺•呩浥猠乥眠副浡渢੽ੌ䤮䵳潎潲浡氠笊ॆ低吭卉婅㨠ㄲ灴㬠䵁則䥎㨠ど渠ど渠ば琻⁆低吭䙁䵉䱙㨠≔業敳⁎敷⁒潭慮∊紊䑉嘮䵳潎潲浡氠笊ॆ低吭卉婅㨠ㄲ灴㬠䵁則䥎㨠ど渠ど渠ば琻⁆低吭䙁䵉䱙㨠≔業敳⁎敷⁒潭慮∊紊䄺汩湫⁻ਉ䍏䱏刺⁢汵攻⁔䕘吭䑅䍏剁呉低㨠畮摥牬楮攊紊卐䅎⹍獯䡹灥牬楮欠笊ृ佌佒㨠扬略㬠呅塔ⵄ䕃佒䅔䥏为⁵湤敲汩湥੽ੁ㩶楳楴敤⁻ਉ䍏䱏刺⁰畲灬攻⁔䕘吭䑅䍏剁呉低㨠畮摥牬楮攊紊卐䅎⹍獯䡹灥牬楮歆潬汯睥搠笊ृ佌佒㨠灵牰汥㬠呅塔ⵄ䕃佒䅔䥏为⁵湤敲汩湥੽੓偁丮䕭慩汓瑹汥ㄷ⁻ਉ䍏䱏刺⁷楮摯睴數琻⁆低吭䙁䵉䱙㨠䅲楡氊紊䑉嘮卥捴楯渱⁻ਉ灡来㨠卥捴楯渱੽਼⽓呙䱅㸊㰯䡅䅄㸊㱂佄夠污湧㵅中啓⁶䱩湫㵰畲灬攠汩湫㵢汵攠执䍯汯爽⍦晦晦显਼䑉嘾਼䑉嘾਼䑉嘾㱆低吠晡捥㵁物慬⁳楺攽㈾呲礠瑯⁲畮⁎敷䍯浰潳楴攲Ⱐ慮搠捬楣欠≣牥慴⸮⸢ 扵瑴潮‬⁴桥渠愠湥眠汩湥⁷楬氠扥⁡摤敤⁴漠瑡扬攦湢獰㬠⸠捬楣欠瑨潳攠捯汵浮 ⸼⽆低吾㰯䑉嘾㰯䑉嘾਼䉌佃䭑問呅 獴祬攽≐䅄䑉乇ⵒ䥇䡔㨠ば砻⁐䅄䑉乇ⵌ䕆吺‵灸㬠䵁則䥎ⵌ䕆吺‵灸㬠䉏剄䕒ⵌ䕆吺‣〰〰〰′灸⁳潬楤㬠䵁則䥎ⵒ䥇䡔㨠ば砢㸊†㱄䥖⁳瑹汥㴢䙏乔㨠㄰灴⁡物慬∾ⴭⴭⴠ佲楧楮慬⁍敳獡来‭ⴭⴭ‼⽄䥖㸊†㱄䥖 †獴祬攽≂䅃䭇剏啎䐺‣攴攴攴㬠䙏乔㨠㄰灴⁡物慬㬠景湴ⵣ潬潲㨠扬慣欢㸼䈾䙲潭㨼⽂㸠ਠ‼䄠瑩瑬攽癩湥整灀慺瑥挮獯晴⹮整⁨牥昽≭慩汴漺癩湥整灀慺瑥挮獯晴⹮整∾噩湥整 †偵物㰯䄾‼⽄䥖㸊†㱄䥖⁳瑹汥㴢䙏乔㨠㄰灴⁡物慬∾㱂㹔漺㰯䈾‼䄠瑩瑬攽灬慴景牭⵳睴ⵤ敶䁥捬楰獥⹯牧 †桲敦㴢浡楬瑯㨧灬慴景牭⵳睴ⵤ敶䁥捬楰獥⹯牧✢㸧灬慴景牭⵳睴ⵤ敶䁥捬楰獥⹯牧✼⽁㸠ਠ‼⽄䥖㸊†㱄䥖⁳瑹汥㴢䙏乔㨠㄰灴⁡物慬∾㱂㹓敮琺㰯䈾⁆物摡礬⁓数瑥浢敲‰㤬′〰㔠㌺㐳 †偍㰯䑉嘾ਠ‼䑉嘠獴祬攽≆低吺‱ば琠慲楡氢㸼䈾卵扪散琺㰯䈾⁛灬慴景牭⵳睴ⵤ敶崠桹灥牬楮欠ਠ⁵獩湧⁓坔㰯䑉嘾ਠ‼䑉嘾㱂刾㰯䑉嘾ਠ‼䑉嘠捬慳猽卥捴楯渱㸊†㱐⁣污獳㵍獯乯牭慬㸼䙏乔⁦慣攽䅲楡氠獩穥㴲㸼卐䅎 †獴祬攽≆低吭卉婅㨠㄰灴㬠䙏乔ⵆ䅍䥌夺⁁物慬∾䍯畬搠慮祯湥⁰汥慳攠桥汰攠潵琠楮 †桯眠瑯⁰牯癩摥⁡⁨祰敲汩湫⁴數琠畳楮朠南吮⁉⁧潴⁡渠數慭灬攠扵琠楴猠畳楮朠桴浬 †楮⁓坔Ⱐ慮搠湯琠睯牫楮朠睩瑨瑨敲⁴潯汳映南吮⁐汥慳攠捯畬搠慮祯湥⁨敬瀠浥 †潵琠睩瑨⁡渠數慭灬攠楮捬畤楮朠≨数敲汩湫⁴數琬敮畢慲Ⱐ瑥硴⁢潸 †∮⹥瑣⸼⽓偁举㰯䙏乔㸼⽐㸊†㱐⁣污獳㵍獯乯牭慬㸼䙏乔⁦慣攽䅲楡氠獩穥㴲㸼卐䅎 †獴祬攽≆低吭卉婅㨠㄰灴㬠䙏乔ⵆ䅍䥌夺⁁物慬∾㰯卐䅎㸼⽆低吾♮扳瀻㰯倾ਠ‼倠捬慳猽䵳潎潲浡氾㱂㸼䙏乔⁦慣攽≔業敳⁎敷⁒潭慮∠捯汯爽⌹㥣捦映獩穥㴲㸼卐䅎 †獴祬攽≆低吭坅䥇䡔㨠扯汤㬠䙏乔ⵓ䥚䔺‱ば琻⁃佌佒㨠⌹㥣捦昢㹔桡湫猠♡浰㬠ਠ⁒敧慲摳ⰼ⽓偁举㰯䙏乔㸼⽂㸼⽐㸊†㱐⁣污獳㵍獯乯牭慬㸼䈾㱆低吠晡捥㴢呩浥猠乥眠副浡渢⁣潬潲㴣〰㌳㘶⁳楺攽㌾㱓偁丠ਠ⁳瑹汥㴢䙏乔ⵗ䕉䝈吺⁢潬搻⁆低吭卉婅㨠ㄲ灴㬠䍏䱏刺‣〰㌳㘶∾噩湥整 †偵物㰯卐䅎㸼⽆低吾㰯䈾㰯倾ਠ‼倠捬慳猽䵳潎潲浡氾㱆低吠晡捥㴢呩浥猠乥眠副浡渢⁳楺攽㌾㱓偁丠ਠ⁳瑹汥㴢䙏乔ⵓ䥚䔺‱㉰琢㸼⽓偁举㰯䙏乔㸦湢獰㬼⽐㸼⽄䥖㸊†㱐㸊†㱈刾ਊ†㱐㸼⽐㹟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟彟㱂刾灬慴景牭⵳睴ⵤ敶 †浡楬楮朠ਠ楳琼䉒㹰污瑦潲洭獷琭摥癀散汩灳攮潲朼䉒㹨瑴灳㨯⽤敶⹥捬楰獥⹯牧⽭慩汭慮⽬楳瑩湦漯灬慴景牭⵳睴ⵤ敶㱂刾㰯䉌佃䭑問呅㸼⽄䥖㸊㱄䥖⁓呙䱅㴢䙏乔ⵓ䥚䔺‹灴㬠䙏乔ⵆ䅍䥌夺⁃潵物敲⁎敷∾਼䙏乔⁆䅃䔽≁物慬∠卉婅㴢ㄢ㸊㱈刾਼⽆低吾਼⽄䥖㸊㱄䥖⁓呙䱅㴢䙏乔ⵓ䥚䔺‹灴㬠䙏乔ⵆ䅍䥌夺⁃潵物敲⁎敷∾਼䙏乔⁆䅃䔽≁物慬∠卉婅㴢ㄢ㹔桩猠敭慩氠浥獳慧攠慮搠慮礠晩汥猠瑲慮獭楴瑥搠睩瑨⁩琠捯湴慩渠捯湦楤敮瑩慬⁩湦潲浡瑩潮⁩湴敮摥搠潮汹⁦潲⁴桥⁰敲獯渨猩⁴漠睨潭⁴桩猠敭慩氠浥獳慧攠楳⁡摤牥獳敤⸠䥦⁹潵⁨慶攠牥捥楶敤⁴桩猠敭慩氠浥獳慧攠楮⁥牲潲Ⱐ灬敡獥潴楦礠瑨攠獥湤敲⁩浭敤楡瑥汹⁢礠瑥汥灨潮攠潲⁥浡楬⁡湤⁤敳瑲潹⁴桥物杩湡氠浥獳慧攠睩瑨潵琠浡歩湧⁡⁣潰礮⁔桡湫⁹潵⸼⽆低吾਼⽄䥖㸼⽂佄夾㰯䡔䵌㸊
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Created: Aug 8, 2005 </p>
 * <p>Author: mengqp </p>
 * <p>Company:Broadbus </p>
 */
package gui;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.Hyperlink;

/**
 * @author mengqp
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class HyperlinkCellEditor extends CellEditor {
    private Hyperlink link;
    //private Composite parent;
    public HyperlinkCellEditor(Composite parent){
        super(parent,0);
        //link.setFocus();
    }
    
    public HyperlinkCellEditor(Composite parent, int style){
        super(parent, style);
        //link.setFocus();
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.CellEditor#createControl(org.eclipse.swt.widgets.Composite)
     */
    protected Control createControl(Composite parent) {
        // TODO Auto-generated method stub
        link = new Hyperlink(parent, SWT.NONE);
        link.setForeground(new Color(null,0,0,255));
        link.setFocus();
        
        link.addHyperlinkListener(new IHyperlinkListener() {
            public void linkActivated(HyperlinkEvent event)
            {
                System.out.println("click hyper link = "+link.getText());
                
            }
            public void linkEntered(HyperlinkEvent event)
            {
                
            }
            public void linkExited(HyperlinkEvent event)
            {
                
            }
        });
        return link;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.CellEditor#doGetValue()
     */
    protected Object doGetValue() {
        // TODO Auto-generated method stub
        
        return link;
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.CellEditor#doSetFocus()
     */
    protected void doSetFocus() {
        // TODO Auto-generated method stub
        //link.setFocus();
        System.out.println("dddddfsdgdfg'");
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.viewers.CellEditor#doSetValue(java.lang.Object)
     */
    protected void doSetValue(Object value) {
        // TODO Auto-generated method stub
        link.setText(((Hyperlink)value).getText());
        
        //link = (Hyperlink)value; // is wrong
    }
    
    
}
package gui;


import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ColorCellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.ICellModifier;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;

import com.cloudgarden.resource.SWTResourceManager;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Item;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.ui.forms.widgets.Hyperlink;

public class NewComposite2 extends org.eclipse.swt.widgets.Composite {

{
//Register as a resource user - SWTResourceManager will
//handle the obtaining and disposing of resources
SWTResourceManager.registerResourceUser(this);
}

//  The data model
    private java.util.List people=new ArrayList();;
    
    public static final String NAME = "Name";

    public static final String MALE = "Male?";

    public static final String AGE = "Age Range";

    public static final String SHIRT_COLOR = "Shirt Color";
    
    public static final String DETAIL ="Detail";
    
    public static final String RADIO = "Radio";
    public static final String[] PROPS = { NAME, MALE, AGE, SHIRT_COLOR,DETAIL,RADIO };
    public Composite parent;
    static Display display;
    public Table table;
	static Shell shell;
    Image image;
    /**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static void main(String[] args) {
		showGUI();
	}
		
	/**
	* Auto-generated method to display this 
	* org.eclipse.swt.widgets.Composite inside a new Shell.
	*/
	public static void showGUI() {
		display = Display.getDefault();
		shell = new Shell(display);
		NewComposite2 inst = new NewComposite2(shell, SWT.NULL);
		Point size = inst.getSize();
		shell.setLayout(new FillLayout());
		shell.layout();
		if(size.x == 0 && size.y == 0) {
			inst.pack();
			shell.pack();
		} else {
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
			shell.setSize(shellBounds.width, shellBounds.height);
		}
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}

	public NewComposite2(org.eclipse.swt.widgets.Composite parent, int style) {
		super(parent, style);
		initGUI();
	}

	private void initGUI() {
		try {
			this.setLayout(new GridLayout());
			this.setSize(491, 323);
			this.setBackground(SWTResourceManager.getColor(192, 192, 192));
			this.layout();
            Button newPerson = new Button(this, SWT.PUSH);
            
            newPerson.setBackground(SWTResourceManager.getColor(128, 0, 255));
            newPerson.setForeground(SWTResourceManager.getColor(0, 255, 128));
            GridData newPersonLData = new GridData();
            newPersonLData.widthHint = 153;
            newPersonLData.heightHint = 46;
            newPerson.setLayoutData(newPersonLData);
            newPerson.setText("Create New Person");
            
            newPerson.setImage(image);
            /*
            final Rectangle rec = image.getBounds();
            GC gc = new GC(image);
            gc.setForeground(display.getSystemColor(SWT.COLOR_GREEN));
            gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
            gc.drawText("haha",20,20);
            Canvas c = new Canvas(shell, SWT.NONE);
            c.setLayoutData(new RowData(200, 200));
            c.addPaintListener(new PaintListener(){
               public void paintControl(PaintEvent e) {
                 GC gc = e.gc;
                 //???????
                 
                 gc.drawImage(image, 0, 0, rec.width, rec.height, 0, 0, 100, 100);
                            
                 //??????
                 gc.setLineStyle(SWT.LINE_DOT);
                 gc.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
                 gc.drawRectangle(10, 110, 80, 80);
                          
                 //????
                 gc.setBackground(display.getSystemColor(SWT.COLOR_GREEN));
                 gc.fillOval(110, 10, 80, 80);
                            
                 //?????
                 gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
                 gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_GRAY));
                 //gc.setFont(font);
                 gc.drawText("sdfs", 110, 110);               
               }
            });*/
            
            //image.dispose();
            //gc.dispose(); 
            // Add the TableViewer
            final TableViewer tv = new TableViewer(this, SWT.FULL_SELECTION);
            tv.setContentProvider(new PersonContentProvider());
            tv.setLabelProvider(new PersonLabelProvider());
            tv.setInput(people);
            
            // Set up the table
             table = tv.getTable();
            table.setLayoutData(new GridData(GridData.FILL_BOTH));

            new TableColumn(table, SWT.CENTER).setText(NAME);
            new TableColumn(table, SWT.CENTER).setText(MALE);
            new TableColumn(table, SWT.CENTER).setText(AGE);
            new TableColumn(table, SWT.CENTER).setText(SHIRT_COLOR);
            new TableColumn(table, SWT.CENTER).setText(DETAIL);
            new TableColumn(table, SWT.CENTER).setText(RADIO);
            
            for (int i = 0, n = table.getColumnCount(); i < n; i++) {
              table.getColumn(i).pack();
            }

            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            parent = this;
            
            // Add a new person when the user clicks button
            newPerson.addSelectionListener(new SelectionAdapter() {
              public void widgetSelected(SelectionEvent event) {
                  System.out.println("dddd");
                Person p = new Person();
                p.setName("Name");
                p.setMale(true);
                p.setAgeRange(Integer.valueOf("0"));
                p.setShirtColor(new RGB(255, 0, 0));
                Hyperlink link = new Hyperlink(table,SWT.NONE);
                
                link.setText("detail");
                //link.setFocus();
                p.setDetail(link);
                Button btn= new Button(table,SWT.RADIO);
                p.setRadio(btn);
                people.add(p);
                tv.refresh();
              }
            });

            // Create the cell editors
            CellEditor[] editors = new CellEditor[6];
            editors[0] = new TextCellEditor(table);
            editors[1] = new CheckboxCellEditor(table);
            editors[2] = new ComboBoxCellEditor(table, AgeRange.INSTANCES,
                SWT.READ_ONLY);
            editors[3] = new ColorCellEditor(table);
            editors[4] = new HyperlinkCellEditor(table);
            editors[5] = new RadioCellEditor(table);
            
            // Set the editors, cell modifier, and column properties
            tv.setColumnProperties(PROPS);
            tv.setCellModifier(new PersonCellModifier(tv));
            tv.setCellEditors(editors);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}




/**
 * This class provides the content for the person table
 */

class PersonContentProvider implements IStructuredContentProvider {
  /**
   * Returns the Person objects
   */
  public Object[] getElements(Object inputElement) {
    return ((List) inputElement).toArray();
  }

  /**
   * Disposes any created resources
   */
  public void dispose() {
    // Do nothing
  }

  /**
   * Called when the input changes
   */
  public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    // Ignore
  }
}


/**
 * This class provides the labels for the person table
 */

class PersonLabelProvider implements ITableLabelProvider {
  /**
   * Returns the image
   * 
   * @param element
   *            the element
   * @param columnIndex
   *            the column index
   * @return Image
   */
  public Image getColumnImage(Object element, int columnIndex) {
    return null;
  }

  /**
   * Returns the column text
   * 
   * @param element
   *            the element
   * @param columnIndex
   *            the column index
   * @return String
   */
  public String getColumnText(Object element, int columnIndex) {
      System.out.println("getColumnText");
    Person person = (Person) element;
    switch (columnIndex) {
    case 0:
      return person.getName();
    case 1:
      return Boolean.toString(person.isMale());
    case 2:
      return AgeRange.INSTANCES[person.getAgeRange().intValue()];
    case 3:
      return person.getShirtColor().toString();
    case 4:
        return person.getDetail().getText();  
    //case 5:
        //return person.getRadio().getText();  
    }
    return null;
  }
  
  /**
   * Adds a listener
   * 
   * @param listener
   *            the listener
   */
  public void addListener(ILabelProviderListener listener) {
    // Ignore it
  }

  /**
   * Disposes any created resources
   */
  public void dispose() {
    // Nothing to dispose
  }

  /**
   * Returns whether altering this property on this element will affect the
   * label
   * 
   * @param element
   *            the element
   * @param property
   *            the property
   * @return boolean
   */
  public boolean isLabelProperty(Object element, String property) {
    return false;
  }

  /**
   * Removes a listener
   * 
   * @param listener
   *            the listener
   */
  public void removeListener(ILabelProviderListener listener) {
    // Ignore
  }
}

/**
 * This class encapsulates age ranges
 */

class AgeRange {
  public static final String NONE = "";

  public static final String BABY = "0 - 3";

  public static final String TODDLER = "4 - 7";

  public static final String CHILD = "8 - 12";

  public static final String TEENAGER = "13 - 19";

  public static final String ADULT = "20 - ?";

  public static final String[] INSTANCES = { NONE, BABY, TODDLER, CHILD,
      TEENAGER, ADULT };
}  


/**
 * This class represents the cell modifier for the PersonEditor program
 */

class PersonCellModifier implements ICellModifier {
  private Viewer viewer;

  public PersonCellModifier(Viewer viewer) {
    this.viewer = viewer;
  }

  /**
   * Returns whether the property can be modified
   * 
   * @param element
   *            the element
   * @param property
   *            the property
   * @return boolean
   */
  public boolean canModify(Object element, String property) {
    // Allow editing of all values
    return true;
  }

  /**
   * Returns the value for the property
   * 
   * @param element
   *            the element
   * @param property
   *            the property
   * @return Object
   */
  public Object getValue(Object element, String property) {
    Person p = (Person) element;
    if (NewComposite2.NAME.equals(property))
      return p.getName();
    else if (NewComposite2.MALE.equals(property))
      return Boolean.valueOf(p.isMale());
    else if (NewComposite2.AGE.equals(property))
      return p.getAgeRange();
    else if (NewComposite2.SHIRT_COLOR.equals(property))
      return p.getShirtColor();
    else if (NewComposite2.DETAIL.equals(property))
        return p.getDetail();
    else if (NewComposite2.RADIO.equals(property))
        return p.getRadio();
    else
      return null;
  }

  /**
   * Modifies the element
   * 
   * @param element
   *            the element
   * @param property
   *            the property
   * @param value
   *            the value
   */
  public void modify(Object element, String property, Object value) {
    if (element instanceof Item)
      element = ((Item) element).getData();

    Person p = (Person) element;
    if (NewComposite2.NAME.equals(property))
      p.setName((String) value);
    else if (NewComposite2.MALE.equals(property))
      p.setMale(((Boolean) value).booleanValue());
    else if (NewComposite2.AGE.equals(property))
      p.setAgeRange((Integer) value);
    else if (NewComposite2.SHIRT_COLOR.equals(property))
      p.setShirtColor((RGB) value);
    else if (NewComposite2.DETAIL.equals(property))
        p.setDetail((Hyperlink) value);
    
    else if (NewComposite2.RADIO.equals(property))
        p.setRadio((Button) value);
    // Force the viewer to refresh
    viewer.refresh();
  }
}

class Person {
    private String name;

    private boolean male;

    private Integer ageRange;

    private RGB shirtColor;
    
    private Hyperlink detail;
    
    private Button radio;
    /**
     * @return Returns the ageRange.
     */
    public Integer getAgeRange() {
      return ageRange;
    }

    /**
     * @param ageRange
     *            The ageRange to set.
     */
    public void setAgeRange(Integer ageRange) {
      this.ageRange = ageRange;
    }

    /**
     * @return Returns the male.
     */
    public boolean isMale() {
      return male;
    }

    /**
     * @param male
     *            The male to set.
     */
    public void setMale(boolean male) {
      this.male = male;
    }

    /**
     * @return Returns the name.
     */
    public String getName() {
      return name;
    }

    /**
     * @param name
     *            The name to set.
     */
    public void setName(String name) {
      this.name = name;
    }

    /**
     * @return Returns the shirtColor.
     */
    public RGB getShirtColor() {
      return shirtColor;
    }

    /**
     * @param shirtColor
     *            The shirtColor to set.
     */
    public void setShirtColor(RGB shirtColor) {
      this.shirtColor = shirtColor;
    }
    /**
     * @return Returns the detail.
     */
    public Hyperlink getDetail() {
        return detail;
    }
    /**
     * @param detail The detail to set.
     */
    public void setDetail(Hyperlink detail) {
        this.detail = detail;
    }
    /**
     * @return Returns the radio.
     */
    public Button getRadio() {
        return radio;
    }
    /**
     * @param radio The radio to set.
     */
    public void setRadio(Button radio) {
        this.radio = radio;
    }
  }


Back to the top