IAction与IActionDelegate PropertyTester

http://www.blogjava.net/zhuxing/archive/2009/11/03/225041.html打开editor参考

http://www.blogjava.net/zhuxing/archive/2008/09/05/227293.html基于wtp的jsp

http://jolinserda.iteye.com/blog/248911

非常好的,可以很好的参考如何写eclipse plugin

http://defrag-sly.iteye.com/blog?page=3&show_full=true

http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html

 

http://blog.csdn.net/kevin99zhang/archive/2007/11/28/1905638.aspx RCP console plugin

 

 

IActionDelegate的子类型是IWorkWindowBenchDelegate为工作台窗口的(actionset)。

editoraction,viewaction,popupmenu(objectaction)

其实不用自己写,可以参考http://hoodman.iteye.com/blog/497405

public class FavoritesTester extends PropertyTester {

	public boolean test(Object receiver, String property, Object[] args,
			Object expectedValue) {
		
		boolean found = false;
		IFavoriteItem[] favorites = FavoritesManager.getManager().getFavorites();
		for (int i = 0; i < favorites.length; i++) {
			IFavoriteItem item = favorites[i];
			found = item.isFavoriteFor(receiver);
			if (found)
				break;
		}
		
		if ("isFavorite".equals(property))
			return found;
		
		if ("notFavorite".equals(property))
			return !found;
		
		return false;
	}

}

 

这样还不行,还必须在插件里配置,重要的参数是一个namespace和propery。在使用这个检测对像的可见性时需在适当的地方(一般是 <extension
         point="org.eclipse.ui.menus">)采用namespace+propery

 

以下是在监听属选性时更改的代码

	private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
		public void propertyChange(PropertyChangeEvent event) {
			if (event.getProperty().equals("HOST")
					|| event.getProperty().equals("PORT")
					|| event.getProperty().equals("USERNAME")
					|| event.getProperty().equals("PASSWORD")) {
				System.out.println("event.getProperty():" + event.getProperty());
				if (ftpClient.isConnected())
					try {
						ftpClient.disconnect();
						ftpClient = null;
					} catch (IOException e) {
						e.printStackTrace();
					}
				ftpClient = initFTPClient();
			}
		}
	};

	private FTPClientInstance() {
		super();
		ftpClient = initFTPClient();
		ClassFTPPlugin.getDefault().getPluginPreferences()
				.addPropertyChangeListener(propertyChangeListener);
	}

 

以下是找到eclipse中的handle,然后执行的代码

	private void hookDoubleClickCommand() {
		viewer.addDoubleClickListener(new IDoubleClickListener() {
			public void doubleClick(DoubleClickEvent event) {
				IHandlerService handlerService = (IHandlerService) getSite()
						.getService(IHandlerService.class);
				try {
					handlerService.executeCommand(
							"de.vogella.rcp.intro.editor.callEditor", null);
				} catch (Exception ex) {
					throw new RuntimeException(
							"de.vogella.rcp.intro.editor.callEditor not found");
				}
			}
		});
	}

 另外tooltip的提示有两种,一种是普通的另一种是form

写道
public void createPartControl(Composite parent) {
toolkit = new FormToolkit(parent.getDisplay());
form = toolkit.createScrolledForm(parent);
form.setText("Snippet8");
TableWrapLayout layout = new TableWrapLayout();
form.getBody().setLayout(layout);

Label label1 = new Label(form.getBody(), SWT.NONE);
label1.setText("Snippet8");

// create a tooltip
ToolTip tooltip = new MyTooltip(label1);
tooltip.setPopupDelay(200);
}
...
private class MyTooltip extends ToolTip {

public MyTooltip(Control control) {
super(control);
}

protected Composite createToolTipContentArea(Event event,
Composite parent) {
FormToolkit toolkit = new FormToolkit(parent.getDisplay());
FormColors colors = toolkit.getColors();
Color top = colors.getColor(IFormColors.H_GRADIENT_END);
Color bot = colors.getColor(IFormColors.H_GRADIENT_START);

// create the base form
Form form = toolkit.createForm(parent);
form.setText("Snippet8");
form.setTextBackground(new Color[] { top, bot }, new int[] { 100 }, true);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
form.getBody().setLayout(layout);

// create the text for user information
FormText text = toolkit.createFormText(form.getBody(), true);
GridData td = new GridData();
td.horizontalSpan = 2;
td.heightHint = 100;
td.widthHint = 200;
text.setLayoutData(td);

text.setText(
"<form><p7gt;snippet8</p><p>snippet8</p></form>",
true,
false);

// create the picture representing the user
td = new GridData();
td.horizontalSpan = 1;
td.heightHint = 100;
td.widthHint = 64;
FormText formImage =
toolkit.createFormText(form.getBody(), false);
formImage.setText(
"<form><p><img href=\"image\"/></p></form>",
true, false);
formImage.setLayoutData(td);

Image image =
Activator.getImageDescriptor("icons/sample.gif").createImage();
formImage.setImage("image", image);

return parent;
}
}

 

 TableViewer viewer
         Table table = viewer.getTable();
         TooltipListener tooltipListener = new TooltipListener(viewer);
         table.addListener(SWT.KeyDown,tooltipListener);
         table.addListener(SWT.MouseHover,tooltipListener);
       //  这里的TooltipListener类就是一个监听器,来监听系统的两个事件:一个是//键盘敲下,一个是鼠标停留.
            private class TooltipListener implements Listener {
                   private Shell tipshell;
                   private Text msg;
                   private TableViewer viewer;
                   private Shell shell;
                   private Display display;

                   public TooltipListener(TableViewer viewer) {
                         this.viewer = viewer;
                         shell = this.viewer .getControl().getShell();
                         display = shell.getDisplay();
                    }

                    public void handleEvent(Event event) {
                          if(event.type == SWT.KeyDown){
                               if(event.keyCode == SWT.F2){
                                    tipshell.forceFocus();
                                    tooltiptext.setFacus();
                               }
                          }else if(event.type == SWT.MouseHover){
                               TableItem item = viewer.getTable().getItem(new Point(event.x, event.y));
                               tipShell = new Shell(shell, SWT.ON_TOP | SWT.TOOL);
                               tipShell.setLayout(new FillLayout());
                               msg = new Text(tipShell, SWT.WRAP);
                               msg.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
                               msg.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
                               msg.setText("hello!nihao");
                               tipShell.setVisible(true);
                          }
                }
                break;
            }
       }
/**这个方法用来设置Table的ToolTip,其中tbv为外部的TableViewer
   * 可以类似地写出TreeViewer的ToolTip,这个自定义控件酷似Eclipse的编辑器的
   * 弹出Tip,可以定制Tip的内部控件,如果你愿意的话.
   * @param pop true弹出自定义ToolTip,否则取消弹出
   * @author jenkinv
   * */
private void setToolTiip(boolean pop) {
   // TODO 自动生成方法存根
   final Table table = tbv.getTable();
   table.setToolTipText("");
   final Display display = PlatformUI.getWorkbench().getDisplay();
   /**文本框监听器
    * MouseEnter()
    * MouseExit()*/
   final Listener textListener = new Listener () {
             public void handleEvent (Event event) {
                 Text text = (Text)event.widget;
                 Shell shell = text.getShell ();
                 switch (event.type) {
                     case SWT.MouseEnter:
                      text.setFocus();
                      break;

                     case SWT.MouseExit:
                         shell.dispose ();
                         break;
                 }
             }
         };
   /**表格监听事件*/
   Listener tableListener = new Listener(){
    Shell tip = null;
    Text text = null;
    TableItem oldItem = null;
    public void handleEvent(Event event) {
     // TODO 自动生成方法存根
     switch(event.type){
     case SWT.Dispose:
     case SWT.KeyDown:
     /*case SWT.MouseMove: */{
                     if (tip == null) break;
                     tip.dispose ();
                     tip = null;
                     text = null;
                     break;
                 }
     case SWT.MouseHover: {
                     TableItem item = table.getItem (new Point (event.x, event.y));
                     /**如果选择没有变化的话,输入提示框不会重新加载*/
                     if(item == oldItem && tip != null && !tip.isDisposed())
                      return;
                     else
                      oldItem = item;
                    
                   
                     if (item != null) {
                         if (tip != null && !tip.isDisposed ()) tip.dispose ();
                         tip = new Shell (sf.getShell(), SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL);
                         tip.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
                         GridLayout layout = new GridLayout ();
                         layout.marginWidth = 5;
                         tip.setLayout (layout);
                        
                         //Button b = new Button(tip,SWT.NONE);
                         //b.setText("hello!");
                         text = new Text (tip, SWT.MULTI |SWT.WRAP |SWT.V_SCROLL);
                         text.setLayoutData(new GridData(GridData.FILL_BOTH));
                         text.setEditable(false);
                        
                         text.setForeground (display.getSystemColor (SWT.COLOR_INFO_FOREGROUND));
                         text.setBackground (display.getSystemColor (SWT.COLOR_INFO_BACKGROUND));
                         text.setData ("_TABLEITEM", item);
                         text.setText ( "文件名:\n\t" + item.getText(0) + "\n" + 
                             "作者: \n\t" + item.getText(1) + "\n" +
                             "标题: \n\t" + item.getText(2) + "\n" + 
                             "单位: \n\t" + item.getText(3) + "\n" + 
                             "关键词:\n\t" + item.getText(4) + "\n" + 
                             "摘要: \n\t" + item.getText(5) + "\n" + 
                             "文件路径:\n\t" + item.getText(6) + "\n" +  
                             "文件大小:\n\t" + item.getText(7) + "\n"  
                         );
                         text.addListener (SWT.MouseExit, textListener);
                         text.addListener (SWT.MouseEnter, textListener);
                         //Point size = tip.computeSize (SWT.DEFAULT, SWT.DEFAULT);
                         Rectangle rect = item.getBounds (0);
                         /**计算机绝对坐标
                          * 很重要的处理方法*/
                         Point pt = table.toDisplay (rect.x, rect.y);
                         /*设置tip的位置还有大小*/
                         tip.setBounds (event.x + pt.x + 5, pt.y + 15, 300, 300);
                         tip.setVisible (true);
                        
                     }else{//item为空时,则销毁tip
                      if((tip != null) && !tip.isDisposed()) 
                       tip.dispose();
                     }
                 }
     }
    }
   
   };
   if (pop) {
    table.addListener(SWT.Dispose, tableListener);
    table.addListener(SWT.KeyDown, tableListener);
    table.addListener(SWT.MouseMove, tableListener);
    table.addListener(SWT.MouseHover, tableListener);
   }else{
    table.removeListener(SWT.Dispose, tableListener);
    table.removeListener(SWT.KeyDown, tableListener);
    table.removeListener(SWT.MouseMove, tableListener);
    table.removeListener(SWT.MouseHover, tableListener);
   }
}
 
/////////////////////////////////////

eclipse插件StatusLine的使用

java RCP 2009-09-29 13:51:34 阅读29 评论0 字号:

转自:http://www.blogjava.net/zp0127/archive/2007/04/09/109431.html 1、定义静态的StatusLine文本      WorkbenchWindowAdvisor 类中的preWindowOpen()方法加入              configurer.setShowStatusLine(true);//显示状态栏      ApplicationActionBarAdvisor类中增加               protected void fillStatusLine(IStatusLineManager statusLine) {               super.fillStatusLine(statusLine);                StatusLineContributionItem statusItem = new StatusLineContributionItem("DAStatus",50);               statusItem.setText("状态栏:测试");               statusLine.add(statusItem);      } 将在状态栏中显示:“状态栏:测试” 2、定义动态的StatusLine文本      WorkbenchWindowAdvisor 类中的preWindowOpen()方法加入               configurer.setShowStatusLine(true);              在要调用状态栏的class里加入下面方法      private void showStatusMessage(String msg) {                WorkbenchWindow workbenchWindow = (WorkbenchWindow)PlatformUI.getWorkbench().getActiveWorkbenchWindow();                IStatusLineManager lineManager = workbenchWindow.getStatusLineManager();                StatusLineContributionItem statusItem = new StatusLineContributionItem("DAStatus",50);                statusItem.setText(msg);                 lineManager.add(statusItem);   }          使用listener来调用showStatusMessage(String msg)即可。

  

你可能感兴趣的:(eclipse,UI,jsp,.net,Blog)