components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/swing/view/CustomObjectsFilter.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panel.swing.view;
       
    27 
       
    28 import java.awt.Component;
       
    29 import com.oracle.solaris.vp.panel.common.model.ManagedObject;
       
    30 import com.oracle.solaris.vp.util.swing.HasComponent;
       
    31 
       
    32 /**
       
    33  * The {@code CustomObjectsFilter} class encapsulates the state and view of an
       
    34  * {@link ObjectsFilter} with a custom component.  Any filter with its own UI,
       
    35  * such as a search or "advanced" filter, would need to subclass this class.
       
    36  */
       
    37 public class CustomObjectsFilter<C extends ManagedObject>
       
    38     extends ObjectsFilter<C> implements HasComponent<Component> {
       
    39 
       
    40     //
       
    41     // Instance data
       
    42     //
       
    43 
       
    44     private Component comp;
       
    45     private CustomObjectsFilterAction action;
       
    46 
       
    47     //
       
    48     // Constructors
       
    49     //
       
    50 
       
    51     public CustomObjectsFilter(String text, Component comp) {
       
    52 	super(text, null);
       
    53 	this.comp = comp;
       
    54     }
       
    55 
       
    56     //
       
    57     // HasComponent methods
       
    58     //
       
    59 
       
    60     /**
       
    61      * Gets the {@code Component} to present to the user.  Note that standard
       
    62      * controls such as okay/cancel buttons, should not be part of this
       
    63      * component.
       
    64      */
       
    65     @Override
       
    66     public Component getComponent() {
       
    67 	return comp;
       
    68     }
       
    69 
       
    70     //
       
    71     // CustomObjectsFilter methods
       
    72     //
       
    73 
       
    74     /**
       
    75      * Gets the {@link CustomObjectsFilterAction} for this {@code
       
    76      * CustomObjectsFilter}.
       
    77      */
       
    78     protected CustomObjectsFilterAction getObjectsFilterAction() {
       
    79 	return action;
       
    80     }
       
    81 
       
    82     /**
       
    83      * Sets the value returned by {@link #getComponent}.
       
    84      */
       
    85     protected void setComponent(Component comp) {
       
    86 	this.comp = comp;
       
    87     }
       
    88 
       
    89     /**
       
    90      * Indicates that this custom control is now being displayed; saves the
       
    91      * given {@link CustomObjectsFilterAction}.
       
    92      *
       
    93      * @param	    action
       
    94      *		    provides hooks that allow this filter to control the filter
       
    95      *		    process
       
    96      */
       
    97     public void start(CustomObjectsFilterAction action) {
       
    98 	this.action = action;
       
    99     }
       
   100 
       
   101     /**
       
   102      * Indicates that this custom control is no longer being displayed; sets
       
   103      * this {@code CustomObjectsFilter}'s {@link CustomObjectsFilterAction} to
       
   104      * {@code null}.
       
   105      *
       
   106      * @param	    applied
       
   107      *		    {@code true} if the filter was applied, {@code false} if it
       
   108      *		    was cancelled
       
   109      */
       
   110     public void stop(boolean applied) {
       
   111 	action = null;
       
   112     }
       
   113 }