CButton a= new CButton("test1",null);
CButton b= new CButton("test1",null);
addAction(a);
addAction(b);
if icon is null,Eclipse Tab still has button,blank button.
But I look forward to no buttons appear,I just want to right-click Eclipse Tab then popup menu.
I think my expectations are reasonable.
Well, changing the behavior because of whether there is an icon or not sounds very counterintuitive for me. Also if a user uses only the keyboard he cannot trigger actions that do not show up on a title/tab.
But of course there is a little hack that you can use. Overriding the “createView” method as in the example below allows you to hide a CButton. For the other CActions similar code can be written (just ask if you need them as well).
import javax.swing.Icon;
import javax.swing.JFrame;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.action.view.ActionViewConverter;
import bibliothek.gui.dock.action.view.ViewTarget;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.action.CButton;
import bibliothek.gui.dock.common.action.core.CommonSimpleButtonAction;
public class Dock02 {
public static void main( String[] args ) {
JFrame frame = new JFrame();
frame.setBounds( 20, 20, 400, 400 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
CControl control = new CControl( frame );
frame.add(control.getContentArea());
DefaultSingleCDockable dockable = new DefaultSingleCDockable("a", "A");
control.addDockable( dockable );
dockable.setVisible( true );
dockable.addAction( new MenuOnlyButton( "Action 1", null ));
dockable.addAction( new MenuOnlyButton( "Action 2", null ));
dockable.addAction( new MenuOnlyButton( "Action 3", null ));
dockable.addAction( new MenuOnlyButton( "Action 4", null ));
frame.setVisible( true );
}
public static class MenuOnlyButton extends CButton{
public MenuOnlyButton( String text, Icon icon ){
super( text, icon );
}
@Override
protected void init(CommonSimpleButtonAction action) {
// we completely ignore "action" and use a custom DockAction that does
// not show up on a title
CommonSimpleButtonAction replacement = new CommonSimpleButtonAction(this){
@Override
public <V> V createView(ViewTarget<V> target, ActionViewConverter converter, Dockable dockable) {
if( target == ViewTarget.TITLE ){
return null;
}
return super.createView(target, converter, dockable);
}
};
super.init( replacement );
}
}
}