Bug 17598 Source->Generate Getter and Setter enabled for read only file
F1 This action is enabled for read-only files. Executing it shows a dialog saying that the file is read-only. The action should be disabled since all other source actions are disabled as well.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/actions/AddGetterSetterAction.java
*/		
	protected void run(IStructuredSelection selection) {
		try {
			IField[] selectedFields= getSelectedFields(selection);
			if (canEnableOn(selectedFields)){
				run(selectedFields[0].getDeclaringType(), selectedFields);
				return;
			}	
			Object firstElement= selection.getFirstElement();
			if (firstElement instanceof IType)
				run((IType)firstElement, new IField[0]);
			else if (firstElement instanceof ICompilationUnit)	
				run(JavaElementUtil.getMainType((ICompilationUnit)firstElement), new IField[0]);
		} catch (CoreException e) {
			JavaPlugin.log(e.getStatus());
			showError(ActionMessages.getString("AddGetterSetterAction.error.actionfailed")); 
		}
				
	}
	
	private boolean canEnable(IStructuredSelection selection) throws JavaModelException{
		if (canEnableOn(getSelectedFields(selection)))
			return true;
			
		if ((selection.size() == 1) && (selection.getFirstElement() instanceof IType))
			return canEnableOn((IType)selection.getFirstElement());
		if ((selection.size() == 1) && (selection.getFirstElement() instanceof ICompilationUnit))
			return canEnableOn(JavaElementUtil.getMainType((ICompilationUnit)selection.getFirstElement()));
		return false;	
	}