1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 14:15:23 +02:00

Added new element wizard classes.

This commit is contained in:
Chris Wiebe 2004-08-06 17:22:58 +00:00
parent abe2eac5c3
commit f8f5b6ab82
3 changed files with 150 additions and 10 deletions

View file

@ -1,3 +1,9 @@
2004-08-06 Chris Wiebe
Added new element wizard classes.
* src/org/eclipse/cdt/internal/ui/wizards/NewElementWizard.java
* src/org/eclipse/cdt/internal/ui/wizards/NewElementWizardPage.java
2004-08-04 Alain Magloire
Provide filters for the Outliner.

View file

@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.wizards;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.cdt.internal.ui.actions.WorkbenchRunnableAdapter;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard;
public abstract class NewElementWizard extends Wizard implements INewWizard {
private IWorkbench fWorkbench;
private IStructuredSelection fSelection;
public NewElementWizard() {
setNeedsProgressMonitor(true);
}
protected void openResource(final IFile resource) {
final IWorkbenchPage activePage= CUIPlugin.getActivePage();
if (activePage != null) {
final Display display= getShell().getDisplay();
if (display != null) {
display.asyncExec(new Runnable() {
public void run() {
try {
IDE.openEditor(activePage, resource, true);
} catch (PartInitException e) {
CUIPlugin.getDefault().log(e);
}
}
});
}
}
}
/**
* Subclasses should override to perform the actions of the wizard.
* This method is run in the wizard container's context as a workspace runnable.
* @param monitor
* @throws InterruptedException
* @throws CoreException
*/
protected abstract void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException;
/**
* Returns the scheduling rule for creating the element.
*/
protected ISchedulingRule getSchedulingRule() {
return ResourcesPlugin.getWorkspace().getRoot(); // look all by default
}
protected boolean canRunForked() {
return true;
}
protected void handleFinishException(Shell shell, InvocationTargetException e) {
String title= NewWizardMessages.getString("NewElementWizard.op_error.title"); //$NON-NLS-1$
String message= NewWizardMessages.getString("NewElementWizard.op_error.message"); //$NON-NLS-1$
ExceptionHandler.handle(e, shell, title, message);
}
/*
* @see Wizard#performFinish
*/
public boolean performFinish() {
IWorkspaceRunnable op= new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
try {
finishPage(monitor);
} catch (InterruptedException e) {
throw new OperationCanceledException(e.getMessage());
}
}
};
try {
getContainer().run(canRunForked(), true, new WorkbenchRunnableAdapter(op, getSchedulingRule()));
} catch (InvocationTargetException e) {
handleFinishException(getShell(), e);
return false;
} catch (InterruptedException e) {
return false;
}
return true;
}
/* (non-Javadoc)
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
fWorkbench= workbench;
fSelection= currentSelection;
}
public IStructuredSelection getSelection() {
return fSelection;
}
public IWorkbench getWorkbench() {
return fWorkbench;
}
protected void selectAndReveal(IResource newResource) {
BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow());
}
}

View file

@ -15,11 +15,9 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.wizard.WizardPage;
/**
* Base class for wizard page responsible to create Java elements. The class
* provides API to update the wizard's statis line and OK button according to
* Base class for wizard page responsible to create C elements. The class
* provides API to update the wizard's status line and OK button according to
* the value of a <code>IStatus</code> object.
*
* @since 2.0
*/
public abstract class NewElementWizardPage extends WizardPage {
@ -34,8 +32,8 @@ public abstract class NewElementWizardPage extends WizardPage {
*/
public NewElementWizardPage(String name) {
super(name);
fPageVisible= false;
fCurrStatus= new StatusInfo();
fPageVisible = false;
fCurrStatus = new StatusInfo();
}
// ---- WizardPage ----------------
@ -45,12 +43,12 @@ public abstract class NewElementWizardPage extends WizardPage {
*/
public void setVisible(boolean visible) {
super.setVisible(visible);
fPageVisible= visible;
fPageVisible = visible;
// policy: wizards are not allowed to come up with an error message
if (visible && fCurrStatus.matches(IStatus.ERROR)) {
StatusInfo status= new StatusInfo();
StatusInfo status = new StatusInfo();
status.setError(""); //$NON-NLS-1$
fCurrStatus= status;
fCurrStatus = status;
}
updateStatus(fCurrStatus);
}
@ -61,7 +59,7 @@ public abstract class NewElementWizardPage extends WizardPage {
* @param status status to apply
*/
protected void updateStatus(IStatus status) {
fCurrStatus= status;
fCurrStatus = status;
setPageComplete(!status.matches(IStatus.ERROR));
if (fPageVisible) {
StatusUtil.applyToStatusLine(this, status);