KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > core > commands > ForEachCommand


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.core.commands;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.debug.core.IRequest;
16 import org.eclipse.debug.core.commands.IEnabledStateRequest;
17
18 /**
19  * A command that operates on each element individually.
20  *
21  * @since 3.3
22  */

23 public abstract class ForEachCommand extends DebugCommand {
24
25     /* (non-Javadoc)
26      * @see org.eclipse.debug.internal.core.commands.DebugCommand#doExecute(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.IRequest)
27      */

28     protected void doExecute(Object JavaDoc[] targets, IProgressMonitor monitor, IRequest request) throws CoreException {
29         for (int i = 0; i < targets.length; i++) {
30             execute(targets[i]);
31             monitor.worked(1);
32         }
33     }
34     
35     protected abstract void execute(Object JavaDoc target) throws CoreException;
36
37     /* (non-Javadoc)
38      * @see org.eclipse.debug.internal.core.commands.DebugCommand#isExecutable(java.lang.Object[], org.eclipse.core.runtime.IProgressMonitor, org.eclipse.debug.core.commands.IEnabledStateRequest)
39      */

40     protected boolean isExecutable(Object JavaDoc[] targets, IProgressMonitor monitor, IEnabledStateRequest request) throws CoreException {
41         for (int i = 0; i < targets.length; i++) {
42             if (!isExecutable(targets[i])) {
43                 return false;
44             }
45             monitor.worked(1);
46         }
47         return true;
48     }
49     
50     protected abstract boolean isExecutable(Object JavaDoc target);
51
52 }
53
Popular Tags