|
| 1 | +/* |
| 2 | +Copyright 2008-2010 Gephi |
| 3 | +Authors : Mathieu Bastian <[email protected]> |
| 4 | +Website : http://www.gephi.org |
| 5 | +
|
| 6 | +This file is part of Gephi. |
| 7 | +
|
| 8 | +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 9 | +
|
| 10 | +Copyright 2011 Gephi Consortium. All rights reserved. |
| 11 | +
|
| 12 | +The contents of this file are subject to the terms of either the GNU |
| 13 | +General Public License Version 3 only ("GPL") or the Common |
| 14 | +Development and Distribution License("CDDL") (collectively, the |
| 15 | +"License"). You may not use this file except in compliance with the |
| 16 | +License. You can obtain a copy of the License at |
| 17 | +http://gephi.org/about/legal/license-notice/ |
| 18 | +or /cddl-1.0.txt and /gpl-3.0.txt. See the License for the |
| 19 | +specific language governing permissions and limitations under the |
| 20 | +License. When distributing the software, include this License Header |
| 21 | +Notice in each file and include the License files at |
| 22 | +/cddl-1.0.txt and /gpl-3.0.txt. If applicable, add the following below the |
| 23 | +License Header, with the fields enclosed by brackets [] replaced by |
| 24 | +your own identifying information: |
| 25 | +"Portions Copyrighted [year] [name of copyright owner]" |
| 26 | +
|
| 27 | +If you wish your version of this file to be governed by only the CDDL |
| 28 | +or only the GPL Version 3, indicate your decision by adding |
| 29 | +"[Contributor] elects to include this software in this distribution |
| 30 | +under the [CDDL or GPL Version 3] license." If you do not indicate a |
| 31 | +single choice of license, a recipient has the option to distribute |
| 32 | +your version of this file under either the CDDL, the GPL Version 3 or |
| 33 | +to extend the choice of license to its licensees as provided above. |
| 34 | +However, if you add GPL Version 3 code and therefore, elected the GPL |
| 35 | +Version 3 license, then the option applies only if the new code is |
| 36 | +made subject to such option by the copyright holder. |
| 37 | +
|
| 38 | +Contributor(s): |
| 39 | +
|
| 40 | +Portions Copyrighted 2011 Gephi Consortium. |
| 41 | +*/ |
| 42 | + |
| 43 | +package org.gephi.desktop.project.actions; |
| 44 | + |
| 45 | +import java.awt.event.ActionEvent; |
| 46 | +import java.util.ArrayList; |
| 47 | +import java.util.List; |
| 48 | +import javax.swing.AbstractAction; |
| 49 | +import org.gephi.desktop.project.ProjectControllerUIImpl; |
| 50 | +import org.gephi.project.api.Workspace; |
| 51 | +import org.openide.awt.ActionID; |
| 52 | +import org.openide.awt.ActionReference; |
| 53 | +import org.openide.awt.ActionRegistration; |
| 54 | +import org.openide.util.ImageUtilities; |
| 55 | +import org.openide.util.Lookup; |
| 56 | +import org.openide.util.NbBundle; |
| 57 | + |
| 58 | +@ActionID(id = "org.gephi.desktop.project.actions.DeleteOtherWorkspaces", category = "Workspace") |
| 59 | +@ActionRegistration(displayName = "#CTL_DeleteOtherWorkspaces", lazy = false) |
| 60 | +public final class DeleteOtherWorkspaces extends AbstractAction { |
| 61 | + |
| 62 | + DeleteOtherWorkspaces() { |
| 63 | + super(NbBundle.getMessage(DeleteOtherWorkspaces.class, "CTL_DeleteOtherWorkspaces")); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void actionPerformed(ActionEvent ev) { |
| 68 | + if (isEnabled()) { |
| 69 | + ProjectControllerUIImpl cui = Lookup.getDefault().lookup(ProjectControllerUIImpl.class); |
| 70 | + Workspace workspace; |
| 71 | + if (ev.getSource() != null && ev.getSource() instanceof Workspace) { |
| 72 | + workspace = (Workspace) ev.getSource(); |
| 73 | + } else { |
| 74 | + workspace = cui.getCurrentProject().getCurrentWorkspace(); |
| 75 | + } |
| 76 | + if (workspace != null) { |
| 77 | + List<Workspace> workspaces = new ArrayList<>(cui.getCurrentProject().getWorkspaces()); |
| 78 | + workspaces.remove(workspace); |
| 79 | + if (!workspaces.isEmpty()) { |
| 80 | + cui.deleteWorkspaces(workspaces); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + @Override |
| 87 | + public boolean isEnabled() { |
| 88 | + return Lookup.getDefault().lookup(ProjectControllerUIImpl.class).canDeleteWorkspace(); |
| 89 | + } |
| 90 | +} |
0 commit comments