Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2006 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: IBM Corporation - initial API and implementation /
 
 package org.eclipse.ant.internal.ui.editor.actions;
 
 import java.net.URL;
 import  org.apache.tools.ant.AntTypeDefinition;
 import  org.apache.tools.ant.ComponentHelper;
 import  org.apache.tools.ant.Project;
 import  org.eclipse.swt.widgets.Shell;
This action opens the selected tasks manual page in an external browser.
 
 public class OpenExternalDocAction extends Action implements IEditorActionDelegate {
 		
 	private static final String COMMAND_ID = "org.eclipse.ant.ui.openExternalDoc"//$NON-NLS-1$
     private AntEditor fEditor;
 	
 	public OpenExternalDocAction() {
 	}
 	
 	public OpenExternalDocAction(AntEditor antEditor) {
 		antEditor;
         IHandlerService handlerService= (IHandlerServiceantEditor.getSite().getService(IHandlerService.class);
         handlerService.activateHandler(new ActionHandler(this));
 		setText(AntEditorActionMessages.getString("OpenExternalDocAction.1")); //$NON-NLS-1$
 		setDescription(AntEditorActionMessages.getString("OpenExternalDocAction.2")); //$NON-NLS-1$
 		setToolTipText(AntEditorActionMessages.getString("OpenExternalDocAction.2")); //$NON-NLS-1$
 	}
 	
     private Shell getShell() {
        return .getEditorSite().getShell();
     }
     
 	private void doAction(AntElementNode node) {
 		Shell shellgetShell();
 		try {
 			URL urlgetExternalLocation(node);
 			if (url != null) {
 				AntUtil.openBrowser(url.toString(), shellgetTitle());
 			} 		
 		} catch (MalformedURLException e) {
            AntUIPlugin.log(e);
         }
 	}
 	
 		URL baseLocationgetBaseLocation();
 		if (baseLocation == null) {
 			return null;
 		}
 
 		String urlStringbaseLocation.toExternalForm();
 
 		StringBuffer pathBuffernew StringBuffer(urlString);
 		if (!urlString.endsWith("/")) { //$NON-NLS-1$
 			pathBuffer.append('/');
 		}
 
 		if (node instanceof AntProjectNode) {
 			pathBuffer.append("using.html#projects"); //$NON-NLS-1$
 		} else if (node instanceof AntTargetNode) {
 			pathBuffer.append("using.html#targets"); //$NON-NLS-1$
 		} else if (node instanceof AntTaskNode) {
 			AntTaskNode taskNode= (AntTaskNodenode;
 			if (.getAntModel().getDefininingTaskNode(taskNode.getTask().getTaskName()) == null) {
 				//not a user defined task
 				appendTaskPath(taskNodepathBuffer);
 			}
 		} 
		try {
			return new URL(pathBuffer.toString());
catch (MalformedURLException e) {
			AntUIPlugin.log(e);
		}
		return null;
	}
	private void appendTaskPath(AntTaskNode nodeStringBuffer buffer) {
	    String taskNamenode.getTask().getTaskName();
	    String taskPartnull;
	    if (taskName.equalsIgnoreCase("path")) {  //$NON-NLS-1$
	        buffer.append("using.html#path"); //$NON-NLS-1$
	        return;
	    } 
	    taskPartgetTaskTypePart(node);
        if (taskPart == null) {
            return;
        }
		buffer.append(taskPart);
		buffer.append('/');
		buffer.append(taskName);
		buffer.append(".html"); //$NON-NLS-1$	
	}
		return new URL(base);
	}
	private String getTitle() {
		return AntEditorActionMessages.getString("OpenExternalDocAction.0"); //$NON-NLS-1$
	}
    /* (non-Javadoc)
     * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
     */
    public void setActiveEditor(IAction actionIEditorPart targetEditor) {
        = (AntEditortargetEditor;
        if ( != null) {
            IHandlerService handlerService= (IHandlerService.getSite().getService(IHandlerService.class);
            handlerService.activateHandler(new ActionHandler(this));
        }
    }
    /* (non-Javadoc)
     * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
     */
    public void run(IAction action) {
        ISelection selection.getSelectionProvider().getSelection();
		AntElementNode nodenull;
		if (selection instanceof ITextSelection) {
			ITextSelection textSelection= (ITextSelection)selection;
			int textOffsettextSelection.getOffset();
			if (model != null) {
				nodemodel.getNode(textOffsetfalse);
			}
			if (node != null) {
				doAction(node);
			}
		}
    }
    /* (non-Javadoc)
     * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
     */
    public void selectionChanged(IAction actionISelection selection) {        
    }
    
    
    private String getTaskTypePart(AntTaskNode node) {
		AntProjectNode projectNodenode.getProjectNode();
    	if (projectNode != null) {
    		Project antProjectprojectNode.getProject();
    		AntTypeDefinition definition= ComponentHelper.getComponentHelper(antProject).getDefinition(node.getTask().getTaskName());
    		if (definition == null) {
    			return null;
    		}
    		String classNamedefinition.getClassName();
    		if (className.indexOf("taskdef") != -1) { //$NON-NLS-1$
    		    if (className.indexOf("optional") != -1) { //$NON-NLS-1$
    		        return "OptionalTasks"//$NON-NLS-1$
    		    } 
    		    return "CoreTasks"//$NON-NLS-1$
    		} else if (className.indexOf("optional") != -1) { //$NON-NLS-1$
    		    return "OptionalTypes"//$NON-NLS-1$
    		} else {
    		    return "CoreTypes"//$NON-NLS-1$
    		}
    	}
    	
        return null;
    }
	/* (non-Javadoc)
	 * @see org.eclipse.jface.action.IAction#run()
	 */
	public void run() {
		run(null);
	}
New to GrepCode? Check out our FAQ X