package autobuildtest.actions; import java.io.ByteArrayInputStream; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceDescription; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; public class SampleAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; public SampleAction() { } public void run(IAction action) { try { MessageDialog.openInformation( window.getShell(), "AutoBuildTest Plug-in", "When you press OK, auto-build will be turned off..."); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject testproj = workspace.getRoot().getProject("testproj"); //$NON-NLS-1$ IWorkspaceDescription description = workspace.getDescription(); description.setAutoBuilding(false); workspace.setDescription(description); MessageDialog.openInformation( window.getShell(), "AutoBuildTest Plug-in", "Auto-build has been turned off; when you press OK, foo.txt will be modified, and then auto-build will immediately be turned on..."); IFile foo = testproj.getFile("foo.txt"); //$NON-NLS-1$ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(new byte[] { '!' }); foo.setContents(byteArrayInputStream, false, true, new NullProgressMonitor()); description = workspace.getDescription(); description.setAutoBuilding(true); workspace.setDescription(description); } catch (CoreException e) { MessageDialog.openInformation( window.getShell(), "AutoBuildTest Plug-in", e.getLocalizedMessage()); } } public void selectionChanged(IAction action, ISelection selection) { } public void dispose() { } public void init(IWorkbenchWindow window) { this.window = window; } }