2016-03-30 5 views
0

これまでに私が管理してきたのは、私が追加したいToolItemが含まれていましたが、このDefaultInformationControlに基づくホバーポップアップが開いているときにはnothigが表示されていたツールバーのToolBarManagerを追加しています。 すべてのToolItemsのテキストとスタイルを指定しました。コントロールを含むツールバーをDefaultInformationControlに追加するにはどうすればよいですか?

私のコードは次のとおりです。

public class JavaTextHover implements IJavaEditorTextHover, ITextHoverExtension{ 
. 
. 
. 
    @Override 
    public IInformationControlCreator getHoverControlCreator() { 
     return new IInformationControlCreator() { 
      public IInformationControl createInformationControl(Shell parent) { 
       ToolBar toolBar = new ToolBar(parent, SWT.NONE); 
       ToolItem itemPush = new ToolItem(toolBar, SWT.PUSH); 
       itemPush.setText("PUSH item"); 
       ToolItem itemCheck = new ToolItem(toolBar, SWT.CHECK); 
       itemCheck.setText("CHECK item"); 
       ToolItem itemRadio1 = new ToolItem(toolBar, SWT.RADIO); 
       itemRadio1.setText("RADIO item 1"); 
       ToolItem itemRadio2 = new ToolItem(toolBar, SWT.RADIO); 
       itemRadio2.setText("RADIO item 2"); 
       ToolItem itemSeparator = new ToolItem(toolBar, SWT.SEPARATOR); 
       Text text = new Text(toolBar, SWT.BORDER | SWT.SINGLE); 
       text.pack(); 
       itemSeparator.setWidth(text.getBounds().width); 
       itemSeparator.setControl(text); 
       final ToolItem itemDropDown = new ToolItem(toolBar, SWT.DROP_DOWN); 
       itemDropDown.setText("DROP_DOWN item"); 
       itemDropDown.setToolTipText("Click here to see a drop down menu ..."); 
       final Menu menu = new Menu(parent, SWT.POP_UP); 
       new MenuItem(menu, SWT.PUSH).setText("Menu item 1"); 
       new MenuItem(menu, SWT.PUSH).setText("Menu item 2"); 
       new MenuItem(menu, SWT.SEPARATOR); 
       new MenuItem(menu, SWT.PUSH).setText("Menu item 3"); 
       itemDropDown.addListener(SWT.Selection, new Listener() { 
        public void handleEvent(Event event) { 
        if(event.detail == SWT.ARROW) { 
         Rectangle bounds = itemDropDown.getBounds(); 
         Point point = toolBar.toDisplay(bounds.x, bounds.y + bounds.height); 
         menu.setLocation(point); 
         menu.setVisible(true); 
        } 
        } 
       }); 
       Listener selectionListener = new Listener() { 
        public void handleEvent(Event event) { 
        ToolItem item = (ToolItem)event.widget; 
        System.out.println(item.getText() + " is selected"); 
        if((item.getStyle() & SWT.RADIO) != 0 || (item.getStyle() & SWT.CHECK) != 0) 
         System.out.println("Selection status: " + item.getSelection()); 
        } 
       }; 
       itemPush.addListener(SWT.Selection, selectionListener); 
       itemCheck.addListener(SWT.Selection, selectionListener); 
       itemRadio1.addListener(SWT.Selection, selectionListener); 
       itemRadio2.addListener(SWT.Selection, selectionListener); 
       itemDropDown.addListener(SWT.Selection, selectionListener); 
       toolBar.pack(); 
       toolBar.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false)); 
       ToolBarManager tbm=new ToolBarManager(toolBar); 
       System.out.println(tbm.getControl().getChildren().length); 
       DefaultInformationControl dic=new DefaultInformationControl(parent, tbm); 
       dic.setBackgroundColor(new Color(null, 98,201,145)); 
       return dic; 
      } 
     }; 
    } 
. 
. 
. 
} 
+0

コードを表示します。 –

+0

ただ、私はあなたがリンクまたは何かを与えることができNlsHoverControlについての情報を見つけることができない、または多分あなたはNLSStringHoverと混同してしまったメインポスト –

答えて

0

私はEclipseのコアコードで見ることができるツールバーを使用しての唯一の例では、物事をこのように行います。

private static final class PresenterControlCreator extends AbstractReusableInformationControlCreator { 

    @Override 
    public IInformationControl doCreateInformationControl(Shell parent) { 
     ToolBarManager tbm= new ToolBarManager(SWT.FLAT); 
     NLSHoverControl iControl= new NLSHoverControl(parent, tbm); 
     OpenPropertiesFileAction openPropertiesFileAction= new OpenPropertiesFileAction(iControl); 
     tbm.add(openPropertiesFileAction); 
     tbm.update(true); 
     return iControl; 
    } 
} 

NLSHoverControlDefaultInformationControlを拡張します。

DefaultInformationControlを作成してツールアイテムではなくアクションを使用した後、ツールバーに追加されます。

static class NLSHoverControl extends DefaultInformationControl implements IInformationControlExtension2 { 

    /** 
    * The NLS control input. 
    */ 
    private NLSHoverControlInput fInput; 

    /** 
    * Creates a resizable NLS hover control with the given shell as parent. 
    * 
    * @param parent the parent shell 
    * @param tbm the toolbar manager or <code>null</code> if toolbar is not desired 
    */ 
    public NLSHoverControl(Shell parent, ToolBarManager tbm) { 
     super(parent, tbm); 

    } 

    /** 
    * Creates an NLS hover control with the given shell as parent. 
    * 
    * @param parent the parent shell 
    * @param tooltipAffordanceString the text to be used in the status field or 
    *   <code>null</code> to hide the status field 
    */ 
    public NLSHoverControl(Shell parent, String tooltipAffordanceString) { 
     super(parent, tooltipAffordanceString); 
    } 

    /** 
    * {@inheritDoc} This control can handle {@link NLSStringHover.NLSHoverControlInput}. 
    */ 
    public void setInput(Object input) { 
     Assert.isLegal(input instanceof NLSHoverControlInput); 

     NLSHoverControlInput info= (NLSHoverControlInput)input; 
     setInformation(info.fInformation); 
     fInput= info; 
    } 

    /** 
    * Returns the control input. 
    * 
    * @return the control input 
    */ 
    public NLSHoverControlInput getInput() { 
     return fInput; 
    } 
} 
+0

に追加しますか? –

+0

いいえ、それは内部クラスが内部で宣言されている 'org.eclipse.jdt.internal.ui.text.java.hover.NLSStringHover' –

+0

追加NlsHoverControl –

関連する問題