|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.cvsclient.commands.grouping; /** * * @author Milos Kleint */ import org.netbeans.modules.javacvs.events.CommandDisplayerAdapter; import org.netbeans.modules.javacvs.commands.*; import org.netbeans.modules.cvsclient.*; import org.netbeans.modules.vcscore.ui.*; import org.netbeans.modules.vcscore.actions.*; import org.netbeans.modules.vcscore.grouping.*; import org.netbeans.modules.vcscore.annotation.*; import org.netbeans.lib.cvsclient.file.FileStatus; import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer; import org.netbeans.lib.cvsclient.command.FileInfoContainer; import org.netbeans.lib.cvsclient.command.status.StatusInformation; import java.util.*; import java.io.*; import org.openide.filesystems.*; import org.openide.*; import org.openide.loaders.*; import org.openide.util.*; import javax.swing.*; import java.awt.Dialog; import java.awt.event.*; import org.openide.DialogDisplayer; public class VerifyGroupDisplayer extends CommandDisplayerAdapter { private int commandCount = 0; private int finishedCommandCount = 0; private boolean errorsOccured = false; private LinkedList localFiles; private LinkedList outOfDateFiles; private LinkedList uptoDateFiles; private NotChangedFilesPanel ncfPanel; private ToAddFilesPanel taPanel; private ToUpdateFilesPanel tuPanel; private Map fileObjectMap; /** Creates new VerifyGroupDisplayer */ public VerifyGroupDisplayer() { localFiles = new LinkedList(); outOfDateFiles = new LinkedList(); uptoDateFiles = new LinkedList(); fileObjectMap = Collections.synchronizedMap(new HashMap()); } public synchronized void addFileObjects(FileObject[] fos) { for (int i = 0; i < fos.length; i++) { File file = FileSystemCommand.toFile(fos[i]); fileObjectMap.put(file, fos[i]); } } public synchronized void increaseNumberOfCommands() { commandCount = commandCount + 1; } public int getNumberOfCommand() { return commandCount; } public synchronized void showFinishedCommand() { // System.out.println("finished 1 status command.."); finishedCommandCount = finishedCommandCount + 1; if (finishedCommandCount == commandCount) { showDialog(); } } public synchronized void showExecutionFailed(Exception exception) { errorsOccured = true; finishedCommandCount = finishedCommandCount + 1; if (finishedCommandCount == commandCount) { showDialog(); } } public synchronized void showFileInfoGenerated(FileInfoContainer info) { if (info.getClass().equals(StatusInformation.class)) { StatusInformation statusInfo = (StatusInformation)info; FileStatus status = statusInfo.getStatus(); // System.out.println("statusinfo=" + statusInfo.getFile().getName()); // System.out.println("status=" + statusInfo.getStatus()); if (status.equals(FileStatus.UNKNOWN)) { localFiles.add(statusInfo); } if (status.equals(FileStatus.UP_TO_DATE)) { uptoDateFiles.add(statusInfo); } if (status.equals(FileStatus.NEEDS_CHECKOUT) || status.equals(FileStatus.NEEDS_MERGE) || status.equals(FileStatus.NEEDS_PATCH)) { outOfDateFiles.add(statusInfo); } } /* if (info.getClass().equals(DefaultFileInfoContainer.class)) { DefaultFileInfoContainer dInfo = (DefaultFileInfoContainer)info; if (dInfo.getType().equals("?")) { StatusInformation sInfo = new StatusInformation(); sInfo.setFile(dInfo.getFile()); sInfo.setStatus(FileStatus.UNKNOWN); localFiles.add(sInfo); } } */ } private void showDialog() { VerifyGroupPanel panel = new VerifyGroupPanel(); boolean nothing = true; if (localFiles.size() > 0) { taPanel = new ToAddFilesPanel(findFOsForFiles(localFiles)); panel.addPanel(taPanel, NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.ToAdd")); nothing = false; } if (outOfDateFiles.size() > 0) { tuPanel = new ToUpdateFilesPanel(findFOsForFiles(outOfDateFiles)); panel.addPanel(tuPanel, NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.ToUpdate")); nothing = false; } if (uptoDateFiles.size() > 0) { List dobjList = getDOForNotChanged(findFOsForFiles(uptoDateFiles)); if (dobjList.size() > 0) { ncfPanel = new NotChangedFilesPanel(dobjList); panel.addPanel(ncfPanel, NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.NotChanged")); nothing = false; } } String title = NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.title"); DialogDescriptor dd = new DialogDescriptor(panel, title); dd.setHelpCtx(new HelpCtx(VerifyGroupPanel.class)); dd.setModal(false); if (nothing) { panel.setDescription(NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.NoProblem")); JButton btnClose = new JButton(NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.closeButton")); Object[] options = new Object[] {btnClose}; dd.setOptions(options); dd.setClosingOptions(options); } else { panel.setDescription(NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.ProblemsFound")); final JButton btnCorrect = new JButton(NbBundle.getBundle(VerifyGroupDisplayer.class).getString("VerifyGroupDisplayer.correctButton")); btnCorrect.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(VerifyGroupDisplayer.class).getString("ACSD_VerifyGroupDisplayer.correctButton")); Object[] options = new Object[] {btnCorrect, DialogDescriptor.CANCEL_OPTION}; dd.setOptions(options); dd.setClosingOptions(options); dd.setButtonListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if (event.getSource().equals(btnCorrect)) { correctGroup(); return; } } }); } final Dialog dial = DialogDisplayer.getDefault().createDialog(dd); SwingUtilities.invokeLater(new Runnable() { public void run() { dial.show(); } }); } private List findFOsForFiles(List fileList) { Iterator it = fileList.iterator(); List foList = new LinkedList(); while (it.hasNext()) { StatusInformation info = (StatusInformation)it.next(); FileObject fo = (FileObject)fileObjectMap.get(info.getFile()); foList.add(fo); } return foList; } private void correctGroup() { if (ncfPanel != null) { performNCFCorrection(); } if (tuPanel != null) { performTUCorrection(); } if (taPanel != null) { performTACorrection(); } } private List getDOForNotChanged(List list) { Iterator it = list.iterator(); Set dobjStat = new HashSet(); while (it.hasNext()) { FileObject fo = (FileObject)it.next(); DataObject dobj = null; try { dobj = DataObject.find(fo); // System.out.println("datablject=" + dobj.getName()); String stat = ((NbJavaCvsFileSystem)dobj.getPrimaryFile().getFileSystem()).getStatus(dobj); // System.out.println("dataobject's status=" + stat); if (stat.equals(NbJavaCvsStatusManager.getInstance().getStatus(NbJavaCvsStatusManager.UPTODATE))) { dobjStat.add(dobj); } } catch (DataObjectNotFoundException exc) { continue; } catch (FileStateInvalidException exc2) { continue; } } Iterator it2 = dobjStat.iterator(); List toReturn = new LinkedList(); while (it2.hasNext()) { toReturn.add(it2.next()); } return toReturn; } public void performTUCorrection() { List list = tuPanel.getFileObjects(); if (list != null && list.size() != 0) { CommandActionSupporter supp = FsCommandFactory.getFsInstance().getSupporter(); UpdateCommandAction act = (UpdateCommandAction)SharedClassObject.findObject(UpdateCommandAction.class, true); FileObject[] fos = new FileObject[list.size()]; fos = (FileObject[])list.toArray(fos); supp.performAction(act, fos); } } public void performNCFCorrection() { java.util.List list = ncfPanel.getSelectedDataObjects(); if (list != null && list.size() > 0) { Iterator it = list.iterator(); while (it.hasNext()) { DataObject obj = (DataObject)it.next(); DataShadow shadow = GroupUtils.findDOInGroups(obj); if (shadow != null) { try { shadow.delete(); } catch (java.io.IOException exc) { } } } } } public void performTACorrection() { java.util.List foList = taPanel.getFileObjects(); if (foList != null && foList.size() != 0) { CommandActionSupporter supp = FsCommandFactory.getFsInstance().getSupporter(); AddCommandAction act = (AddCommandAction)SharedClassObject.findObject(AddCommandAction.class, true); FileObject[] fos = new FileObject[foList.size()]; fos = (FileObject[])foList.toArray(fos); supp.performAction(act, fos); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.