|
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.common.control; |
|
27 |
|
28 import java.util.Map; |
|
29 import com.oracle.solaris.vp.panel.common.ClientContext; |
|
30 import com.oracle.solaris.vp.panel.common.action.ActionAbortedException; |
|
31 import com.oracle.solaris.vp.panel.common.model.PanelDescriptor; |
|
32 |
|
33 /** |
|
34 * The {@code QuitControl} class is a convenience {@link Control} that shuts |
|
35 * down the running client instance when navigated to. |
|
36 */ |
|
37 public class QuitControl<P extends PanelDescriptor> extends DefaultControl<P> { |
|
38 // |
|
39 // Static data |
|
40 // |
|
41 |
|
42 public static final String ID = "quit"; |
|
43 |
|
44 // |
|
45 // Constructors |
|
46 // |
|
47 |
|
48 public QuitControl(ClientContext context) { |
|
49 super(ID, null, context); |
|
50 } |
|
51 |
|
52 public QuitControl(P descriptor) { |
|
53 super(ID, null, descriptor); |
|
54 } |
|
55 |
|
56 // |
|
57 // Control methods |
|
58 // |
|
59 |
|
60 @Override |
|
61 public boolean isBrowsable() { |
|
62 // This Control should not be visible to the user |
|
63 return false; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Unconditionally calls {@link ClientContext#closeInstance}. |
|
68 */ |
|
69 @Override |
|
70 public void start(Navigator navigator, Map<String, String> parameters) |
|
71 throws NavigationAbortedException, InvalidParameterException, |
|
72 NavigationFailedException { |
|
73 |
|
74 super.start(navigator, parameters); |
|
75 |
|
76 // schedule this on the navigation thread so that it runs after this |
|
77 // navigation completes |
|
78 navigator.asyncExec( |
|
79 new Runnable() { |
|
80 @Override |
|
81 public void run() { |
|
82 try { |
|
83 getClientContext().closeInstance(true); |
|
84 } catch (ActionAbortedException ignore) { |
|
85 } |
|
86 } |
|
87 }); |
|
88 } |
|
89 } |