upload tizen1.0 source
[sdk/ide/common-eplugin.git] / org.tizen.common / src / org / tizen / common / handler / ClipboardHandler.java
1 /*\r
2 *  Common\r
3 *\r
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.\r
5 *\r
6 * Contact: \r
7 * Kangho Kim <kh5325.kim@samsung.com>\r
8\r
9 * Licensed under the Apache License, Version 2.0 (the "License");\r
10 * you may not use this file except in compliance with the License.\r
11 * You may obtain a copy of the License at\r
12 *\r
13 * http://www.apache.org/licenses/LICENSE-2.0\r
14 *\r
15 * Unless required by applicable law or agreed to in writing, software\r
16 * distributed under the License is distributed on an "AS IS" BASIS,\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18 * See the License for the specific language governing permissions and\r
19 * limitations under the License.\r
20 *\r
21 * Contributors:\r
22 * - S-Core Co., Ltd\r
23 *\r
24 */\r
25 \r
26 package org.tizen.common.handler;\r
27 \r
28 import org.eclipse.core.commands.AbstractHandler;\r
29 import org.eclipse.core.commands.ExecutionEvent;\r
30 import org.eclipse.core.commands.ExecutionException;\r
31 import org.eclipse.swt.dnd.Clipboard;\r
32 import org.eclipse.ui.handlers.HandlerUtil;\r
33 \r
34 /**\r
35  * Superclass for clipboard related handlers providing safe creation and\r
36  * disposal of the {@link Clipboard}.\r
37  */\r
38 public abstract class ClipboardHandler extends AbstractHandler {\r
39         public Object execute(ExecutionEvent event) throws ExecutionException {\r
40                 Clipboard clipboard = new Clipboard(HandlerUtil.getActiveShell(event)\r
41                                 .getDisplay());\r
42                 try {\r
43                         return execute(event, clipboard);\r
44                 } finally {\r
45                         clipboard.dispose();\r
46                 }\r
47         }\r
48 \r
49         protected abstract Object execute(ExecutionEvent event, Clipboard clipboard)\r
50                         throws ExecutionException;\r
51 }