Update of /cvsroot/eclipse-ccase/net.sourceforge.eclipseccase.ui/src/net/sourceforge/eclipseccase/ui/wizards
In directory vz-cvs-4.sog:/tmp/cvs-serv18032/src/net/sourceforge/eclipseccase/ui/wizards
Added Files:
Tag: mike_diff_checkin
CheckinWizardPage.java message.properties ResizableWizard.java
CheckinWizard.java
Log Message:
First version of new checkin
--- NEW FILE: ResizableWizard.java ---
/*******************************************************************************
* Copyright (c) 2004, 2005 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 net.sourceforge.eclipseccase.ui.wizards;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.wizard.Wizard;
public class ResizableWizard extends Wizard {
private final int DEFAULT_WIDTH;
private final int DEFAULT_HEIGHT;
private static final String BOUNDS_HEIGHT_KEY = "width"; //$NON-NLS-1$
private static final String BOUNDS_WIDTH_KEY = "height"; //$NON-NLS-1$
final String fSectionName;
public ResizableWizard(String sectionName, IDialogSettings settings) {
this(sectionName, settings, 300, 400);
}
protected ResizableWizard(String sectionName, IDialogSettings settings, int defaultWidth, int defaultHeight) {
DEFAULT_WIDTH= defaultWidth;
DEFAULT_HEIGHT= defaultHeight;
fSectionName= sectionName;
setDialogSettings(settings);
}
protected static int open(Shell shell, ResizableWizard wizard) {
final WizardDialog dialog= new WizardDialog(shell, wizard);
dialog.setMinimumPageSize(wizard.loadSize());
return dialog.open();
}
public void saveSize() {
final Rectangle bounds= getContainer().getCurrentPage().getControl().getParent().getClientArea();
final IDialogSettings settings= getDialogSettings();
if (settings == null)
return;
IDialogSettings section= settings.getSection(fSectionName);
if (section == null)
section= settings.addNewSection(fSectionName);
section.put(BOUNDS_WIDTH_KEY, bounds.width);
section.put(BOUNDS_HEIGHT_KEY, bounds.height);
}
public Point loadSize() {
final Point size= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT);
final IDialogSettings settings= getDialogSettings();
if (settings == null)
return size;
final IDialogSettings section= settings.getSection(fSectionName);
if (section == null)
return size;
try {
size.x= section.getInt(BOUNDS_WIDTH_KEY);
size.y= section.getInt(BOUNDS_HEIGHT_KEY);
} catch (NumberFormatException e) {
}
return size;
}
public boolean performFinish() {
saveSize();
return true;
}
}
--- NEW FILE: CheckinWizard.java ---
package net.sourceforge.eclipseccase.ui.wizards;
import net.sourceforge.eclipseccase.ui.ClearCaseUI;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.core.runtime.*;
import org.eclipse.jface.operation.*;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import java.io.*;
import org.eclipse.ui.*;
import org.eclipse.ui.ide.IDE;
/**
* This is a sample new wizard. Its role is to create a new file
* resource in the provided container. If the container resource
* (a folder or a project) is selected in the workspace
* when the wizard is opened, it will accept it as the target
* container. The wizard creates one file with the extension
* "mpe". If a sample multi-page editor (also available
* as a template) is registered for the same extension, it will
* be able to open it.
*/
public class CheckinWizard extends ResizableWizard implements INewWizard {
private CheckinWizardPage page;
private IResource [] resources;
private IStructuredSelection selection;
public static final String CHECKIN_WIZARD_DIALOG_SETTINGS = "CheckinWizard"; //$NON-NLS-1$
/**
* Constructor for SampleNewWizard.
*/
public CheckinWizard(IResource [] resources) {
//FIXME:mike changed to ResizableWizard.
super(CHECKIN_WIZARD_DIALOG_SETTINGS,ClearCaseUI.getInstance().getDialogSettings());
setNeedsProgressMonitor(true);
this.resources = resources;
}
/**
* Adding the page to the wizard.
*/
public void addPages() {
page = new CheckinWizardPage(resources);
addPage(page);
}
/**
* This method is called when 'Finish' button is pressed in
* the wizard. We will create an operation and run it
* using wizard as execution context.
*/
public boolean performFinish() {
final String containerName = page.getContainerName();
final String fileName = page.getFileName();
IRunnableWithProgress op = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
try {
doFinish(containerName, fileName, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
};
try {
getContainer().run(true, false, op);
} catch (InterruptedException e) {
return false;
} catch (InvocationTargetException e) {
Throwable realException = e.getTargetException();
MessageDialog.openError(getShell(), "Error", realException.getMessage());
return false;
}
return true;
}
/**
* The worker method. It will find the container, create the
* file if missing or just replace its contents, and open
* the editor on the newly created file.
*/
private void doFinish(
String containerName,
String fileName,
IProgressMonitor monitor)
throws CoreException {
// create a sample file
monitor.beginTask("Creating " + fileName, 2);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(new Path(containerName));
if (!resource.exists() || !(resource instanceof IContainer)) {
throwCoreException("Container \"" + containerName + "\" does not exist.");
}
IContainer container = (IContainer) resource;
final IFile file = container.getFile(new Path(fileName));
try {
InputStream stream = openContentStream();
if (file.exists()) {
file.setContents(stream, true, true, monitor);
} else {
file.create(stream, true, monitor);
}
stream.close();
} catch (IOException e) {
}
monitor.worked(1);
monitor.setTaskName("Opening file for editing...");
getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
IDE.openEditor(page, file, true);
} catch (PartInitException e) {
}
}
});
monitor.worked(1);
}
/**
* We will initialize file contents with a sample text.
*/
private InputStream openContentStream() {
String contents =
"This is the initial file contents for *.mpe file that should be word-sorted in the Preview page of the multi-page editor";
return new ByteArrayInputStream(contents.getBytes());
}
private void throwCoreException(String message) throws CoreException {
IStatus status =
new Status(IStatus.ERROR, "Test", IStatus.OK, message, null);
throw new CoreException(status);
}
/**
* We will accept the selection in the workbench to see if
* we can initialize from it.
* @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.selection = selection;
}
}
--- NEW FILE: CheckinWizardPage.java ---
package net.sourceforge.eclipseccase.ui.wizards;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Composite;
import net.sourceforge.eclipseccase.ui.CommentDialogArea;
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
import java.io.File;
import net.sourceforge.clearcase.ClearCase;
import net.sourceforge.eclipseccase.ClearCasePlugin;
import net.sourceforge.eclipseccase.ClearCaseProvider;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogPage;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.dialogs.ContainerSelectionDialog;
/**
* The "New" wizard page allows setting the container for the new file as well
* as the file name. The page will only accept file name without the extension
* OR with the extension that matches the expected one (mpe).
*/
public class CheckinWizardPage extends WizardPage {
private Text containerText;
private Text commentText;
private String comment;
String[] comments = new String[0];
private Text fileText;
private static final int WIDTH_HINT = 350;
private static final int HEIGHT_HINT = 150;
private IResource[] resource;
private Combo previousCommentsCombo;
/**
* Constructor for SampleNewWizardPage.
*
* @param pageName
*/
public CheckinWizardPage(IResource[] resource) {
super("wizardPage");
setTitle("Checkin");
setDescription("No useful title here yet!");
this.resource = resource;
}
/**
* @see IDialogPage#createControl(Composite)
*/
public void createControl(Composite parent) {
Composite container = createGrabbingComposite(parent, 1);
setControl(container);
// START Comment
final Label commentLabel = new Label(container, SWT.NULL);
commentLabel.setText("Edit the &comment:");
commentText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData(GridData.FILL_BOTH);
data.widthHint = WIDTH_HINT;
data.heightHint = HEIGHT_HINT;
commentText.setLayoutData(data);
commentText.selectAll();
//Tabbing?
commentText.addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN && (e.stateMask & SWT.CTRL) != 0) {
e.doit = false;
// CommentDialogArea.this.signalCtrlEnter();
}
}
});
// Combo for comments
final Label prevCommentLabel = new Label(container, SWT.NULL);
prevCommentLabel.setText("Choose a &previously entered comment:");
previousCommentsCombo = new Combo(container, SWT.READ_ONLY);
GridData data2 = new GridData(GridData.FILL_HORIZONTAL);
data2.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
previousCommentsCombo.setLayoutData(data2);
// Initialize the values before we register any listeners so
// we don't get any platform specific selection behavior
// (see bug 32078: http://bugs.eclipse.org/bugs/show_bug.cgi?id=32078)
initializeValues();
previousCommentsCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int index = previousCommentsCombo.getSelectionIndex();
if (index != -1) {
commentText.setText(comments[index]);
}
}
});
// END Comment
SashForm horizontalSash = new SashForm(container, SWT.HORIZONTAL|SWT.SMOOTH);
horizontalSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
//Add changed resource area.
//Add a Tree viewer.
// Label label = new Label(container, SWT.NULL);
// label.setLayoutData(new GridData());
// label.setText("Edit the &comment:");
//
// GridData data = null;
//
// text = new Text(container, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL |
// SWT.V_SCROLL);
// data = new GridData(GridData.FILL_BOTH);
// data.widthHint = WIDTH_HINT;
// data.heightHint = HEIGHT_HINT;
// text.setLayoutData(data);
// text.selectAll();
// text.addTraverseListener(new TraverseListener() {
//
// public void keyTraversed(TraverseEvent e) {
// if (e.detail == SWT.TRAVERSE_RETURN && (e.stateMask & SWT.CTRL) != 0)
// {
// e.doit = false;
// //CommentDialogArea.this.signalCtrlEnter();
// }
// }
// });
//
// text.setText(comment);
// text.addModifyListener(new ModifyListener() {
//
// public void modifyText(ModifyEvent e) {
// comment = text.getText();
// }
// });
//
// label = new Label(container, SWT.NULL);
// label.setLayoutData(new GridData());
// label.setText("Choose a &previously entered comment:");
//
// previousCommentsCombo = new Combo(container, SWT.READ_ONLY);
// data = new GridData(GridData.FILL_HORIZONTAL);
// data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
// previousCommentsCombo.setLayoutData(data);
//
// // Initialize the values before we register any listeners so
// // we don't get any platform specific selection behavior
// // (see bug 32078:
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=32078)
// initializeValues();
//
// previousCommentsCombo.addSelectionListener(new SelectionAdapter() {
//
// @Override
// public void widgetSelected(SelectionEvent e) {
// int index = previousCommentsCombo.getSelectionIndex();
// if (index != -1) {
// text.setText(comments[index]);
// }
// }
// });
// END Comment
// Button button = new Button(container, SWT.PUSH);
// button.setText("Browse...");
// button.addSelectionListener(new SelectionAdapter() {
// @Override
// public void widgetSelected(SelectionEvent e) {
// handleBrowse();
// }
// });
// label = new Label(container, SWT.NULL);
// label.setText("&File name:");
//
// fileText = new Text(container, SWT.BORDER | SWT.SINGLE);
// gd = new GridData(GridData.FILL_HORIZONTAL);
// fileText.setLayoutData(gd);
// fileText.addModifyListener(new ModifyListener() {
// public void modifyText(ModifyEvent e) {
// dialogChanged();
// }
// });
//
// dialogChanged();
}
private void addComments(Composite parent) {
// String maybeComment = "";
// int maybeDepth = IResource.DEPTH_ZERO;
// CommentDialog dlg;
// if (!ClearCasePreferences.isUseClearDlg() &&
// ClearCasePreferences.isCommentCheckin()) {
// //IResource[] resources = getSelectedResources();
// String extCoComment = getLastExtCoComment(resource);
// if (!extCoComment.equalsIgnoreCase("")) {
// dlg = new CommentDialog(parent, "Checkin comment", extCoComment);
// } else {
// dlg = new CommentDialog(getShell(), "Checkin comment");
// }
// if (dlg.open() == Window.CANCEL)
// return;
// maybeComment = dlg.getComment();
// maybeComment = dlg.getComment();
// maybeDepth = dlg.isRecursive() ? IResource.DEPTH_INFINITE :
// IResource.DEPTH_ZERO;
// }
}
private void initializeValues() {
// populate the previous comment list
for (int i = 0; i < comments.length; i++) {
previousCommentsCombo.add(flattenText(comments[i]));
}
// We don't want to have an initial selection
// (see bug 32078: http://bugs.eclipse.org/bugs/show_bug.cgi?id=32078)
previousCommentsCombo.setText(""); //$NON-NLS-1$
}
/**
* Uses the standard container selection dialog to choose the new value for
* the container field.
*/
private void handleBrowse() {
ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "Select new file container");
if (dialog.open() == Window.OK) {
Object[] result = dialog.getResult();
if (result.length == 1) {
containerText.setText(((Path) result[0]).toString());
}
}
}
/**
* Ensures that both text fields are set.
*/
private void dialogChanged() {
IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
String fileName = getFileName();
if (getContainerName().length() == 0) {
updateStatus("File container must be specified");
return;
}
if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
updateStatus("File container must exist");
return;
}
if (!container.isAccessible()) {
updateStatus("Project must be writable");
return;
}
if (fileName.length() == 0) {
updateStatus("File name must be specified");
return;
}
if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
updateStatus("File name must be valid");
return;
}
int dotLoc = fileName.lastIndexOf('.');
if (dotLoc != -1) {
String ext = fileName.substring(dotLoc + 1);
if (ext.equalsIgnoreCase("mpe") == false) {
updateStatus("File extension must be \"mpe\"");
return;
}
}
updateStatus(null);
}
private void updateStatus(String message) {
setErrorMessage(message);
setPageComplete(message == null);
}
public String getContainerName() {
return containerText.getText();
}
public String getFileName() {
return fileText.getText();
}
/**
* Method retrieves the check-out comment for the last modified resource
* outside the eclipse workspace.
*
* @param resources
* @return comment
*/
private String getLastExtCoComment(IResource[] resources) {
long lastModificationTime = 0L;
IResource lastModifiedResource = null;
StringBuffer comment = new StringBuffer();
String lastComment = "";
for (IResource iResource : resources) {
String path = iResource.getLocation().toOSString();
File file = new File(path);
long modificationTime = file.lastModified();
if (modificationTime == 0L) {
ClearCasePlugin.log(IStatus.WARNING, "Could not access resource," + iResource.getName(), null);
}
if (modificationTime > lastModificationTime) {
lastModificationTime = modificationTime;
lastModifiedResource = iResource;
}
}
// get comment for last modified resource.
ClearCaseProvider provider = ClearCaseProvider.getClearCaseProvider(lastModifiedResource);
if (provider != null) {
String element = lastModifiedResource.getLocation().toOSString();
String[] output = provider.describe(element, ClearCase.FORMAT, "%c");
if (output.length > 0) {
for (int i = 0; i < output.length; i++) {
comment.append(output[i] + "\n");
}
}
lastComment = comment.toString();
}
return lastComment;
}
/**
* Flatten the text in the multiline comment
*
* @param string
* @return String
*/
String flattenText(String string) {
StringBuffer buffer = new StringBuffer(string.length() + 20);
boolean skipAdjacentLineSeparator = true;
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (c == '\r' || c == '\n') {
if (!skipAdjacentLineSeparator) {
buffer.append("/");
}
skipAdjacentLineSeparator = true;
} else {
buffer.append(c);
skipAdjacentLineSeparator = false;
}
}
return buffer.toString();
}
protected Composite createGrabbingComposite(Composite parent, int numColumns) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setFont(parent.getFont());
// GridLayout
GridLayout layout = new GridLayout();
layout.numColumns = numColumns;
composite.setLayout(layout);
// GridData
GridData data = new GridData();
data.verticalAlignment = GridData.FILL;
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
data.grabExcessVerticalSpace = true;
composite.setLayoutData(data);
return composite;
}
}
--- NEW FILE: message.properties ---
CommitWizard = Enter a comment for the commit operation.
|