Hi Tony,

I am working on a similar application in which I wish to only use a
subset of the toolbar. To accommodate this, I created an extension point
that allows you to specify which IToolManager to use. You then specify
in your plugin_customization.ini file (which lives with your
application's .product file). 

The new extension is specified at
net.refractions.udig.project.ui.toolManagers. Define your own that
subclasses
net.refractions.udig.project.ui.internal.tool.display.ToolManager and
override contributeToCoolBar(). 

The method I used to display only the actions I wanted was rather hacky:
I had a filter (a String[] of tool IDs, taken from the tool plugin.xml
files), and in createActionToolToolbar and createModalToolToolbar if the
tool's ID is not present in the filter, it is not added to the tool bar.
I also skipped the use of "categories".

I've attached the ToolManager implementation I am using.

Note that there are also new customization extension points similar to
this one: 

net.refractions.udig.ui.menuBuilders
net.refractions.udig.ui.workbenchConfigurations

Hope this helps. I'll try and detail in the coming days more of the
changes I have made recently.

Richard

On Thu, 2007-03-22 at 12:36 +0100, [EMAIL PROTECTED] wrote:
> Hi,
> I have some problems with handle the udig specific actions, toolbar
> and coolbar items. We are using plugins of udig in one perspective of
> our application. At first I removed some of the (modal) actions out of
> the plugin.xml files of the (udig)plugins since not all tools are
> needed by the users and some will irritate them. (the main focus of
> the application has nothing to do with gis, just one perspective)
>  
> In those perspectives where no mapeditor is shown we don't need the
> udig actions. I tried to remove them but I wasn't very successfull.
> The udig actions are managed by the ToolManager but I found no
> possibility to hide all (modal) actions / coolbars. 
>  
> Finally I wrote an PerspectiveAdapter which closes all mapeditors when
> changing to another perspective. This works fine and all udig specific
> actions are removed. If one switches back to the perspective, a new
> mapeditor opens with the old map and all actions are visibile again.
> The sole thing which is a little bit disturbing is that the renderer
> contacts all wms servers again for rendering. This takes some
> seconds. 
>  
> I'm not sure if this is the best way. Is there a better way to remove
> the udig specific actions out of the tool/coolbar?
>  
> thanks,
> tony roth
> _______________________________________________
> User-friendly Desktop Internet GIS (uDig)
> http://udig.refractions.net
> http://lists.refractions.net/mailman/listinfo/udig-devel
package net.refractions.flightline.ui.internal;

import net.refractions.udig.project.ui.internal.tool.display.ActionToolCategory;
import net.refractions.udig.project.ui.internal.tool.display.ModalItem;
import net.refractions.udig.project.ui.internal.tool.display.ModalToolCategory;
import net.refractions.udig.project.ui.internal.tool.display.ToolManager;
import net.refractions.udig.project.ui.internal.tool.display.ToolProxy;

import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.SubCoolBarManager;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IWorkbenchPart;

public class FlightlineToolManager extends ToolManager {

    @Override
    public void contributeGlobalActions( IWorkbenchPart part, IActionBars bars ) {
        super.contributeGlobalActions(part, bars);
    }

    @Override
    public void contributeToCoolBar( SubCoolBarManager cbmanager, IActionBars bars ) {
        cbmanager.setVisible(true);
        createActionToolToolbar(cbmanager);
        createModalToolToolbar(cbmanager);
    }
    

    private void createActionToolToolbar( SubCoolBarManager cbmanager ) {
        ToolBarManager manager = new ToolBarManager(SWT.FLAT);
        
        /*
         * TODO this should probably be thrown into an extension point
         */
        String[] validItems = new String[] {
                "net.refractions.udig.tools.refresh",
                "net.refractions.udig.tools.cancel",
                "net.refractions.udig.tool.default.ZoomIn",
                "net.refractions.udig.tools.ZoomExtent",
                "net.refractions.udig.tool.default.ZoomIn",
                "net.refractions.udig.tool.default.ZoomOut",
                "net.refractions.udig.tool.default.commit",
                "net.refractions.udig.tool.default.rollback",
                
                                
                
        };

        manager.add(getBACKWARD_HISTORYAction());
        manager.add(getFORWARD_HISTORYAction());
        for( String id : categoryIds ) {
            ActionToolCategory category = findActionCategory(id);
            if (category != null) {
                for (ModalItem item : category.items) {
                    ToolProxy toolProxy = ((ToolProxy) item);
                    if( toolProxy.isOnToolbar()) {
                        for (String validItem : validItems) {
                            if (validItem.equals(item.getId())) {
                                manager.add(toolProxy.getAction());
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (manager != null && manager.getItems().length > 0)
            cbmanager.add(manager);
    }
    
    private void createModalToolToolbar( SubCoolBarManager cbmanager ) {
        ToolBarManager manager = new ToolBarManager(SWT.FLAT);
        
        /*
         * TODO this should probably be thrown into an extension point
         */
        String[] validItems = new String[] {
                "net.refractions.udig.tools.Zoom",
                "net.refractions.udig.tools.Pan",
                "net.refractions.udig.tool.default.ZoomIn",
                "net.refractions.udig.tools.pointEdit",  
                "net.refractions.udig.tools.selectionTool"
        };

        for( String id : categoryIds ) {
            ModalToolCategory modalCategory = findModalCategory(id);
            if (modalCategory != null) {
                for( ModalItem item : modalCategory ) {
                    ToolProxy tool = (ToolProxy) item;

                    if (tool.isOnToolbar()) {
                        for (String validItem : validItems) {
                            if (validItem.equals(item.getId())) {
                                manager.add(tool.getAction());
                                break;
                            }
                        }
                    }
                    
                }
            }
        }
        if (manager != null && manager.getItems().length > 0)
            cbmanager.add(manager);
    }

    @Override
    public void contributeToMenu( IMenuManager manager ) {
        super.contributeToMenu(manager);
    }

}
_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to