|
From: Mikael P. <er...@us...> - 2012-02-16 09:48:42
|
Update of /cvsroot/eclipse-ccase/net.sourceforge.eclipseccase.ui/src/net/sourceforge/eclipseccase/ui/wizards In directory vz-cvs-4.sog:/tmp/cvs-serv24542/src/net/sourceforge/eclipseccase/ui/wizards Added Files: message.properties ElementSelectionLabelProvider.java CompareDialog.java ResizableWizard.java ElementSelectionContentProvider.java CheckinWizard.java Log Message: Refactoring of names --- 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 org.eclipse.core.runtime.SubProgressMonitor; import java.util.Arrays; import net.sourceforge.eclipseccase.ClearCasePreferences; import net.sourceforge.eclipseccase.ClearDlgHelper; import net.sourceforge.eclipseccase.ui.DirectoryLastComparator; import net.sourceforge.eclipseccase.ui.console.ConsoleOperationListener; import org.eclipse.core.resources.IResource; import net.sourceforge.eclipseccase.ClearCaseProvider; 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; private ClearCaseProvider provider; public static final String CHECKIN_WIZARD_DIALOG_SETTINGS = "CheckinWizard"; //$NON-NLS-1$ public static final int SCALE = 100; /** * Constructor for CheckinWizard. */ public CheckinWizard(IResource[] resources, ClearCaseProvider provider) { super(CHECKIN_WIZARD_DIALOG_SETTINGS, ClearCaseUI.getInstance().getDialogSettings()); setNeedsProgressMonitor(true); this.resources = resources; this.provider = provider; } /** * Adding the page to the wizard. */ public void addPages() { page = new CheckinWizardPage("Checkin", resources, provider); 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 comment = page.getCommentText(); final IResource[] resources = page.getResourceList(); final boolean recursive = page.isRecursive(); /* * Build a process that will run using the IRunnableWithProgress * interface so the UI can handle showing progress bars, etc. */ IRunnableWithProgress op = new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException { try { /* * The method (see below) which contains the "real" * implementation code. */ doFinish(provider, comment, resources, recursive, monitor); } catch (CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }; try { /* This runs the process built above in a seperate thread */ 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 make the actual checkin of the resource. */ private void doFinish(ClearCaseProvider provider, String comment, IResource[] resources, boolean isRecursive, IProgressMonitor monitor) throws CoreException { int depth = isRecursive ? IResource.DEPTH_INFINITE : IResource.DEPTH_ZERO; monitor.beginTask("Checking in...", resources.length); ConsoleOperationListener opListener = new ConsoleOperationListener(monitor); Arrays.sort(resources, new DirectoryLastComparator()); for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; if (provider != null) { provider.setComment(comment); provider.setOperationListener(opListener); provider.checkin(new IResource[] { resource }, depth, new SubProgressMonitor(monitor, 1 * SCALE)); } } } /** * 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: ElementSelectionContentProvider.java --- package net.sourceforge.eclipseccase.ui.wizards; import java.util.List; import org.eclipse.core.resources.IProject; import net.sourceforge.eclipseccase.ui.ResourceComparator; import java.util.Arrays; import org.eclipse.core.resources.IWorkspaceRoot; import java.util.ArrayList; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IResource; import org.eclipse.ui.model.WorkbenchContentProvider; public class ElementSelectionContentProvider extends WorkbenchContentProvider { private IResource[] resources; @Override public Object getParent(Object element) { return ((IResource) element).getParent(); } @Override public boolean hasChildren(Object element) { if (element instanceof IContainer) return true; else return false; } @Override public Object[] getElements(Object inputElement) { return getChildren(inputElement); } @Override public Object[] getChildren(Object parentElement) { if (parentElement instanceof IContainer){ return getChildResources((IContainer) parentElement); } return new Object[0]; } private IResource[] getChildResources(IContainer parent) { ArrayList<IResource> children = new ArrayList<IResource>(); for (int i = 0; i < resources.length; i++) { if (!(resources[i] instanceof IContainer)) { IContainer parentFolder = resources[i].getParent(); if (parentFolder != null && parentFolder.equals(parent) && !children.contains(parentFolder)) { children.add(resources[i]); } } } IResource[] childArray = new IResource[children.size()]; children.toArray(childArray); return childArray; } } --- NEW FILE: ElementSelectionLabelProvider.java --- package net.sourceforge.eclipseccase.ui.wizards; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ISharedImages; import java.util.ArrayList; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IContainer; import org.eclipse.swt.graphics.Image; import org.eclipse.jface.viewers.LabelProvider; public class ElementSelectionLabelProvider extends LabelProvider { // private WorkbenchLabelProvider wlp = new WorkbenchLabelProvider(); private ArrayList<IResource> resourceList; @Override public Image getImage(Object element) { String imageKey = ISharedImages.IMG_OBJ_ELEMENT; if (element instanceof IContainer) imageKey = ISharedImages.IMG_OBJ_FOLDER; return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); // Image image = null; // if (resourceList.contains(element)) { // image = super.getImage(element); // } // // return image; } @Override public String getText(Object element) { String text = null; IResource resource = (IResource) element; return resource.getFullPath().makeRelative().toString(); } } --- NEW FILE: CompareDialog.java --- package net.sourceforge.eclipseccase.ui.wizards; import java.util.ResourceBundle; import org.eclipse.compare.*; import org.eclipse.compare.internal.ResizableDialog; import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.*; public class CompareDialog extends ResizableDialog { private static final CompareConfiguration cc = new CompareConfiguration(); private CompareViewerSwitchingPane compareViewerPane; private ICompareInput myInput; @SuppressWarnings("restriction") protected CompareDialog(Shell shell, ResourceBundle bundle) { super(shell, bundle); this.setShellStyle(SWT.CLOSE); cc.setLeftEditable(false); cc.setRightEditable(false); } void compare(ICompareInput input) { myInput = input; cc.setLeftLabel(myInput.getLeft().getName()); cc.setLeftImage(myInput.getLeft().getImage()); cc.setRightLabel(myInput.getRight().getName()); cc.setRightImage(myInput.getRight().getImage()); if (compareViewerPane != null) { compareViewerPane.setInput(myInput); } } /* * (non Javadoc) Creates SWT control tree. */ @Override protected synchronized Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); getShell().setText("Compare"); //$NON-NLS-1$ compareViewerPane = new ViewerSwitchingPane(composite, SWT.BORDER | SWT.FLAT); compareViewerPane.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL)); if (myInput != null) { compareViewerPane.setInput(myInput); } applyDialogFont(composite); return composite; } class ViewerSwitchingPane extends CompareViewerSwitchingPane { ViewerSwitchingPane(Composite parent, int style) { super(parent, style, false); } @Override protected Viewer getViewer(Viewer oldViewer, Object input) { if (input instanceof ICompareInput) return CompareUI.findContentViewer(oldViewer, (ICompareInput) input, this, cc); return null; } @Override public void setImage(Image image) { // don't show icon } } } --- NEW FILE: message.properties --- CommitWizard = Enter a comment for the commit operation. |