Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2009 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 Brock Janiczak <brockj@tpg.com.au> - Bug 161536 Warn user when committing resources with problem markers Brock Janiczak <brockj@tpg.com.au> - Bug 177519 [Wizards] Adopt new IResource.findMaxProblemSeverity API Brock Janiczak <brockj@tpg.com.au> - Bug 166333 [Wizards] Show diff in CVS commit dialog /
 
 package org.eclipse.team.internal.ccvs.ui.wizards;
 
 import java.util.*;
 
 import  org.eclipse.swt.widgets.Shell;
A wizard to commit the resources whose synchronization state is given in form of a set of SyncInfo.
 
 public class CommitWizard extends ResizableWizard {
     
 	public static final String COMMIT_WIZARD_DIALOG_SETTINGS = "CommitWizard"//$NON-NLS-1$
 	
    
An operation to add and commit resources to a CVS repository.
 
     public static class AddAndCommitOperation extends CVSOperation {
         
         private final IResource[] fAllResources;
         private final String fComment;
         
         private Map fModesForExtensionsForOneTime;
         private Map fModesForNamesForOneTime;
         
         private IResource[] fNewResources;
         
         public AddAndCommitOperation(IWorkbenchPart partIResource[] allResourcesIResource[] newResourcesString comment) {
             super(part);
              = allResources;
              = newResources;
             .;
              = comment;
         }
         
         public void setModesForExtensionsForOneTime(Map modes) {
         	if (modes != null)
         		modes;
         }
         
         public void setModesForNamesForOneTime(Map modes) {
         	if (modes != null)
         		modes;
         }
         
         protected void execute(IProgressMonitor monitorthrows CVSExceptionInterruptedException {
             try {
             	monitor.beginTask(null, (. + .) * 100);
             	if (. > 0) {
 	                final AddOperation opnew AddOperation(getPart(), RepositoryProviderOperation.asResourceMappers());
 	                op.addModesForExtensions();
 	                op.addModesForNames();
 	                op.run(Policy.subMonitorFor(monitor. * 100));
            	}
                if (. > 0) {
	                CommitOperation commitOperation = new CommitOperation(getPart(), RepositoryProviderOperation.asResourceMappers(), new Command.LocalOption[0], ) {
	                	public boolean consultModelsForMappings() {
	                		// Do not consult models from the commit wizard
	                		return false;
	                	}
	                };
					commitOperation.run(Policy.subMonitorFor(monitor. * 100));
                }
            } catch (InvocationTargetException e) {
                throw CVSException.wrapException(e);
            } finally {
            	monitor.done();
            }
        }
        
        protected String getJobName() {
            return .
        }
        
        protected String getTaskName() {
            return .
        }
        /*
         * Set the job listener. It will only recieve scheduled and done
         * events as these are what are used by a sync model operation
         * to show busy state in the sync view.
         */
		protected void setJobChangeListener(IJobChangeListener jobListener) {
			this. = jobListener;
		}
		/* (non-Javadoc)
		 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#done(org.eclipse.core.runtime.jobs.IJobChangeEvent)
		 */
		public void done(IJobChangeEvent event) {
			super.done(event);
			if ( != null)
		}
		/* (non-Javadoc)
		 * @see org.eclipse.core.runtime.jobs.IJobChangeListener#scheduled(org.eclipse.core.runtime.jobs.IJobChangeEvent)
		 */
		public void scheduled(IJobChangeEvent event) {
			super.scheduled(event);
			if ( != null)
		}
    }
    
    private final IResource[] fResources;
    private IResource[] fUnaddedDiffs;
    
    
    public CommitWizard(SyncInfoSet infosthrows CVSException {
        this(infos.getResources());
    }
    
    public CommitWizard(final IResource [] resourcesthrows CVSException {
        
        super(, CVSUIPlugin.getPlugin().getDialogSettings());
        
        setNeedsProgressMonitor(true);
        
        resources;
        ResourceMapping[] mappings = Utils.getResourceMappings(resources);
         = createWorkspaceParticipant(mappingsgetShell());
        getAllOutOfSync();
    }
	private ModelSynchronizeParticipant createWorkspaceParticipant(ResourceMapping[] selectedMappings, Shell shell) {
		ISynchronizationScopeManager manager = WorkspaceSubscriberContext.createWorkspaceScopeManager(selectedMappingstrue, CommitAction.isIncludeChangeSets(shell.));
		return new CommitWizardParticipant(WorkspaceSubscriberContext.createContext(manager.), this);
	}
	public CommitWizard(SyncInfoSet infosIJobChangeListener jobListenerthrows CVSException {
		this(infos);
		this. = jobListener;
	}
	private void getAllOutOfSync() throws CVSException {
		try {
			Job.getJobManager().join(contextnull);
catch (InterruptedException e) {
		}
	}
    public boolean hasOutgoingChanges() {
    	IResourceDiffTree tree = getDiffTree();
		return tree != null && tree.hasMatchingDiffs(ResourcesPlugin.getWorkspace().getRoot().getFullPath(), new FastDiffFilter() {
			public boolean select(IDiff diff) {
				return AbstractCommitAction.hasLocalChange(diff);
			}
		});
    }
    
    boolean hasConflicts() {
    	IResourceDiffTree tree = getDiffTree();
		return tree != null && tree.hasMatchingDiffs(ResourcesPlugin.getWorkspace().getRoot().getFullPath(), new FastDiffFilter() {
			public boolean select(IDiff diff) {
				if (diff instanceof IThreeWayDiff) {
					IThreeWayDiff twd = (IThreeWayDiffdiff;
				}
				return false;
			}
		});
	}
    
    public int getHighestProblemSeverity() {
    	int mostSeriousSeverity = -1;
    	
    	for (int i = 0; i < resources.lengthi++) {
    		IResource resource = resources[i];
    		try {
    			int severity = resource.findMaxProblemSeverity(.true.);
    			if (severity > mostSeriousSeverity) {
					mostSeriousSeverity = severity;
				}
catch (CoreException e) {
			}
    	}
    	
    	return mostSeriousSeverity;
    }
	}
        return ;
    }
        return ;
    }
        return ;
    }
    public boolean canFinish() {
        final IWizardPage currentgetContainer().getCurrentPage();
        if (current ==  &&  != null)
            return false;
        return super.canFinish();
    }
    public boolean performFinish() {
        
        final String comment.getComment(getShell());
        if (comment == null)
            return false;
        
        IResource[] resources = AbstractCommitAction.getOutgoingChanges(getDiffTree(), .getTraversalsToCommit(), null);
        if (resources.length == 0)
			return true;
        
        final IResource[] unadded;
        try {
            unadded = getUnaddedResources(resources);
        } catch (CVSException e1) {
            return false;
        }
        
        final IResource[] files = getFiles(resources);
        
        final AddAndCommitOperation operationnew AddAndCommitOperation(getPart(), filesunaddedcomment);
        if ( != null)
        	operation.setJobChangeListener();
        
        if ( != null) {
            final Map extensionsToSavenew HashMap();
            final Map extensionsNotToSavenew HashMap();
            
            .getModesForExtensions(extensionsToSaveextensionsNotToSave);
            CommitWizardFileTypePage.saveExtensionMappings(extensionsToSave);
            operation.setModesForExtensionsForOneTime(extensionsNotToSave);
            
            final Map namesToSavenew HashMap();
            final Map namesNotToSavenew HashMap();
            
            .getModesForNames(namesToSavenamesNotToSave);
            CommitWizardFileTypePage.saveNameMappings(namesToSave);
            operation.setModesForNamesForOneTime(namesNotToSave);
        }
        
        try {
            operation.run();
        } catch (InvocationTargetException e) {
            return false;
        } catch (InterruptedException e) {
            return false;
        }
        
        .finish();
        return super.performFinish();
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.team.internal.ccvs.ui.wizards.ResizableWizard#performCancel()
     */
    public boolean performCancel() {
    	return super.performCancel();
    }
    public void addPages() {
        
        final Collection namesnew HashSet();
        final Collection extensionsnew HashSet();
        getUnknownNamesAndExtension(namesextensions);
        
        if (names.size() + extensions.size() > 0) {
            new CommitWizardFileTypePage(extensionsnames); 
            addPage();
        }
        
        new CommitWizardCommitPage(this);
        addPage();
        
        super.addPages();
    }
    public void dispose() {
        .dispose();
        super.dispose();
    }
    
    public static void run(IWorkbenchPart part, Shell shellIResource [] resourcesthrows CVSException {
        try {
			CommitWizard commitWizard = new CommitWizard(resources);
			commitWizard.setPart(part);
			run(shellcommitWizard);
			// Ignore
		}
    }
    
    private void setPart(IWorkbenchPart part) {
		this. = part;
	}
	public static void run(Shell shellSyncInfoSet infosIJobChangeListener jobListenerthrows CVSException {
        try {
			run(shellnew CommitWizard(infosjobListener));
			// Ignore
		}
    }
	public static void run(IWorkbenchPart part, Shell shellfinal ResourceTraversal[] traversalsthrows CVSException {
        try {
        	final IResource [][] resources = new IResource[][] { null };
    			public void run(IProgressMonitor monitorthrows InvocationTargetExceptionInterruptedException {
    				try {
    					resources[0] = getDeepResourcesToCommit(traversalsmonitor);
    				} catch (CoreException e) {
    					throw new InvocationTargetException(e);
    				}
    			}
    		});
			run(partshellresources[0]);
			// Ignore
catch (InvocationTargetException e) {
			throw CVSException.wrapException(e);
catch (InterruptedException e) {
			// Ignore
		}
	}
	private IWorkbenchPart getPart() {
    	if ( != null)
    		return ;
        return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPartService().getActivePart();
    }
    
    private static void run(Shell shellCommitWizard wizard) {
        if (!wizard.hasOutgoingChanges()) {
            MessageDialog.openInformation(shell..); // 
        } else {
        	int highestProblemSeverity = wizard.getHighestProblemSeverity();
        	IPreferenceStore preferenceStore = CVSUIPlugin.getPlugin().getPreferenceStore();
			switch (highestProblemSeverity) {
				String allowCommitsWithWarnings = preferenceStore.getString(.);
				if (..equals(allowCommitsWithWarnings) || ..equals(allowCommitsWithWarnings)) {
					if (. != warningDialog.getReturnCode()) {
						return;
					}
				}
				break;
				String allowCommitsWithErrors = preferenceStore.getString(.);
				if (..equals(allowCommitsWithErrors) || ..equals(allowCommitsWithErrors)) {
					if (. != errorDialog.getReturnCode()) {
						return;
					}
				}
				break;
			}
        	open(shellwizard);
        }
    }
    protected static int open(Shell shellResizableWizard wizard) {
        final WizardDialog dialognew WizardDialog(shellwizard);
        dialog.setPageSize(wizard.loadSize());
        return dialog.open();
    }
    
    private void getUnknownNamesAndExtension(IResource[] resourcesCollection namesCollection extensions) {
    	final IFileContentManager manager= Team.getFileContentManager();
    	for (int i = 0; i < resources.lengthi++) {
    		IResource local = resources[i];
    		if (local instanceof IFile && manager.getType((IFile)local) == .) {
    			final String extensionlocal.getFileExtension();
    			if (extension != null && !manager.isKnownExtension(extension)) {
    				extensions.add(extension);
    			}
    			final String namelocal.getName();
    			if (extension == null && name != null && !manager.isKnownFilename(name))
    				names.add(name);
    		}
    	}
    }
    
	private IResource[] getUnaddedResources(IResource[] resourcesthrows CVSException {
		List/*<IResource>*/ unadded = new ArrayList/*<IResource>*/();
		for (int i = 0; i < resources.lengthi++) {
			if (!isAdded(resources[i])) {
				unadded.add(resources[i]);
			}
		}
		return (IResource[]) unadded.toArray(new IResource[0]);
	}
	private IResource[] getFiles(IResource[] resources) {
		final List files = new ArrayList();
		for (int i = 0; i < resources.lengthi++) {
			if (resources[i].getType() == .)
				files.add(resources[i]);
		}
		return (IResource[]) files.toArray(new IResource[0]);
	}
    private static boolean isAdded(IResource resourcethrows CVSException {
        final ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
        if (cvsResource.isFolder()) {
            return ((ICVSFolder)cvsResource).isCVSFolder();
        }
        return cvsResource.isManaged();
    }
    private static IResource[] getDeepResourcesToCommit(ResourceTraversal[] traversalsIProgressMonitor monitorthrows CoreException {
        List roots = new ArrayList();
        for (int j = 0; j < traversals.lengthj++) {
            ResourceTraversal traversal = traversals[j];
            IResource[] resources = traversal.getResources();
            if (traversal.getDepth() == .) {
                roots.addAll(Arrays.asList(resources));
            } else if (traversal.getDepth() == .) {
                collectShallowFiles(resourcesroots);
            } else if (traversal.getDepth() == .) {
                collectShallowFiles(resourcesroots);
                for (int k = 0; k < resources.lengthk++) {
                    IResource resource = resources[k];
                    if (resource.getType() != .) {
                        collectShallowFiles(members(resource), roots);
                    }
                }
            }
        }
        return (IResource[]) roots.toArray(new IResource[roots.size()]);
    }
    private static IResource[] members(IResource resourcethrows CoreException {
        return CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber().members(resource);
    }
    private static void collectShallowFiles(IResource[] resourcesList roots) {
        for (int k = 0; k < resources.lengthk++) {
            IResource resource = resources[k];
            if (resource.getType() == .)
                roots.add(resource);
        }
    }
}    

New to GrepCode? Check out our FAQ X