001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.collab.channel.filesharing.ui.actions;
042:
043: import com.sun.collablet.CollabException;
044:
045: import org.openide.cookies.EditorCookie;
046: import org.openide.filesystems.FileObject;
047: import org.openide.loaders.DataObject;
048: import org.openide.loaders.DataShadow;
049: import org.openide.nodes.Node;
050: import org.openide.util.*;
051: import org.openide.util.actions.*;
052:
053: import java.awt.event.*;
054: import java.io.IOException;
055:
056: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
057: import org.netbeans.modules.collab.channel.filesharing.FilesharingEventNotifierFactory;
058: import org.netbeans.modules.collab.channel.filesharing.FilesharingEventProcessorFactory;
059: import org.netbeans.modules.collab.channel.filesharing.event.DeleteFileEvent;
060: import org.netbeans.modules.collab.channel.filesharing.filehandler.CollabFileHandler;
061: import org.netbeans.modules.collab.channel.filesharing.mdc.CollabEvent;
062: import org.netbeans.modules.collab.channel.filesharing.mdc.EventContext;
063: import org.netbeans.modules.collab.channel.filesharing.mdc.EventNotifier;
064: import org.netbeans.modules.collab.channel.filesharing.mdc.EventProcessor;
065: import org.netbeans.modules.collab.channel.filesharing.util.FileshareUtil;
066: import org.netbeans.modules.collab.core.Debug;
067:
068: /**
069: * UnShareFileAction
070: *
071: * @author Ayub Khan
072: * @version 1.0
073: */
074: public class UnShareFileAction extends SystemAction {
075: ////////////////////////////////////////////////////////////////////////////
076: // Class variables
077: ////////////////////////////////////////////////////////////////////////////
078: public static final String UNSHARE_FILE_ACTION = NbBundle
079: .getMessage(UnShareFileAction.class,
080: "LBL_UnshareFileAction_ActionName"); //"Unshare"
081:
082: ////////////////////////////////////////////////////////////////////////////
083: // Instant variables
084: ////////////////////////////////////////////////////////////////////////////
085: FilesharingContext context = null;
086: Node node = null;
087:
088: public UnShareFileAction(FilesharingContext context, Node node) {
089: this .context = context;
090: this .node = node;
091: }
092:
093: public String getName() {
094: return UNSHARE_FILE_ACTION; //NoI18n
095: }
096:
097: protected String iconResource() {
098: return "org/openide/resources/actions/empty.gif";
099: }
100:
101: public HelpCtx getHelpCtx() {
102: return HelpCtx.DEFAULT_HELP;
103: }
104:
105: protected boolean asynchronous() {
106: return true;
107: }
108:
109: public void actionPerformed(ActionEvent actionEvent) {
110: Debug.out.println("Unshare File, actionPerformed"); //NoI18n
111:
112: FileObject fObj = null;
113:
114: try {
115: DataShadow lnk = (DataShadow) node
116: .getCookie(DataShadow.class);
117: EditorCookie ec = null;
118:
119: if (lnk != null) {
120: Debug.out.println("SPN Original node path: "
121: + lnk.getOriginal().getPrimaryFile().getPath());
122: ec = (EditorCookie) lnk.getCookie(EditorCookie.class);
123: fObj = lnk.getOriginal().getPrimaryFile();
124: } else {
125: DataObject d = (DataObject) node
126: .getCookie(DataObject.class);
127: ec = (EditorCookie) d.getCookie(EditorCookie.class);
128: fObj = d.getPrimaryFile();
129: }
130:
131: if (ec != null) {
132: ec.open();
133: ec.close();
134: }
135:
136: Debug.out.println("Unshare file: " + fObj.getPath()); //NoI18n
137: node.getParentNode().getChildren().remove(
138: new Node[] { node });
139:
140: if (!context.getSharedFileGroupManager().isShared(fObj)) {
141: return;
142: }
143:
144: CollabFileHandler fh = context.getSharedFileGroupManager()
145: .getFileHandler(fObj);
146: FileshareUtil.deleteFileLink(fh.getName(), context);
147:
148: EventContext evContext = new EventContext(DeleteFileEvent
149: .getEventID(), fh);
150: CollabEvent ce = new DeleteFileEvent(evContext);
151:
152: //create a notifer
153: EventNotifier fileChangeNotifier = null;
154: EventProcessor ep = FilesharingEventProcessorFactory
155: .getDefault().createEventProcessor(
156: context.getProcessorConfig(), context);
157: fileChangeNotifier = FilesharingEventNotifierFactory
158: .getDefault().createEventNotifier(
159: context.getNotifierConfig(), ep);
160:
161: if (fileChangeNotifier != null) {
162: fileChangeNotifier.notify(ce);
163: }
164:
165: //node detroy
166: // node.destroy();
167: // } catch (IOException iox) {
168: // iox.printStackTrace(Debug.out);
169: } catch (CollabException e) {
170: e.printStackTrace(Debug.out);
171: }
172: }
173: }
|