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.vmd.api.model.presenters.actions;
042:
043: import org.netbeans.modules.vmd.api.model.Debug;
044: import org.netbeans.modules.vmd.api.model.Presenter;
045:
046: /**
047: * This presenters specifies delete ability.
048: *
049: * @author David Kaspar
050: */
051: public abstract class DeletePresenter extends Presenter {
052:
053: /**
054: * Returns whether the related component could be deleted.
055: * @return the deletable state
056: */
057: DeletableState canDelete() {
058: return DeletableState.ALLOWED;
059: }
060:
061: /**
062: * Returns whether the related component could be listed in the delete dialog.
063: * @return true, if could be listed; false, if it should be deleted silently
064: */
065: boolean isSilent() {
066: return false;
067: }
068:
069: /**
070: * Perform the deletion logic for the relation component.
071: * You should also invoke deletion of related components that cannot live without this component.
072: * For deletion invocation, use <code>DeletePresenter.invokeDeletion</code> method.
073: */
074: protected abstract void delete();
075:
076: /**
077: * Creates a DeletePresentet that disallows to list the component in the confirm-deletion dialog.
078: * @return the delete presenter
079: */
080: public static Presenter createSilentDeletionPresenter() {
081: return new DeletePresenter() {
082: @Override
083: boolean isSilent() {
084: return true;
085: }
086:
087: protected void delete() {
088: }
089: };
090: }
091:
092: /**
093: * Creates a DeletePresenter that disallows to delete related component.
094: * @return the delete presenter
095: */
096: public static Presenter createIndeliblePresenter() {
097: return new DeletePresenter() {
098:
099: @Override
100: DeletableState canDelete() {
101: return DeletableState.DISALLOWED;
102: }
103:
104: protected void delete() {
105: throw Debug.illegalState();
106: }
107:
108: };
109: }
110:
111: /**
112: * Creates a DeletePresenter that disallows to delete related component by user only.
113: * The component could be deleted by indirect deletion still.
114: * @return the delete presenter
115: */
116: public static Presenter createUserIndeliblePresenter() {
117: return new DeletePresenter() {
118:
119: @Override
120: DeletableState canDelete() {
121: return DeletableState.DISALLOWED_FOR_USER_ONLY;
122: }
123:
124: protected void delete() {
125: }
126:
127: };
128: }
129:
130: // /**
131: // * Creates a presenter which invokes deletion of referenced components by a specified property name.
132: // * @param propertyName the property name of property of the related component
133: // * @return the delete presenter
134: // */
135: // public static Presenter createReferencedComponentsPresenter (final String propertyName) {
136: // return new DeletePresenter() {
137: // protected DeletableState canDelete () {
138: // ArrayList<DesignComponent> children = new ArrayList<DesignComponent> ();
139: // Debug.collectAllComponentReferences (getComponent ().readProperty (propertyName), children);
140: // return DeletePresenter.canDelete (children);
141: // }
142: //
143: // protected void delete () {
144: // ArrayList<DesignComponent> children = new ArrayList<DesignComponent> ();
145: // Debug.collectAllComponentReferences (getComponent ().readProperty (propertyName), children);
146: // DeletePresenter.delete (children);
147: // }
148: // };
149: // }
150:
151: }
|