]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/PartNameListener.java
Merge remote-tracking branch 'origin/svn' commit 'ccc1271c9d6657fb9dcf4cf3cb115fa0c8c...
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / PartNameListener.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.swt;\r
13 \r
14 \r
15 import java.util.function.Consumer;\r
16 \r
17 import org.simantics.db.common.procedure.adapter.ListenerSupport;\r
18 import org.simantics.db.procedure.Listener;\r
19 import org.simantics.utils.ObjectUtils;\r
20 \r
21 /**\r
22  * @author Tuukka Lehtonen\r
23  */\r
24 public class PartNameListener extends PartNameProcedure implements Listener<String> {\r
25 \r
26     private boolean         disposed = false;\r
27     private ListenerSupport support;\r
28 \r
29     public PartNameListener(Consumer<String> updateCallback) {\r
30         super(updateCallback);\r
31         support = null;\r
32     }\r
33 \r
34     public PartNameListener(Consumer<String> updateCallback, ListenerSupport support) {\r
35         super(updateCallback);\r
36         this.support = support;\r
37     }\r
38 \r
39     @Override\r
40     public void exception(Throwable t) {\r
41         if (support != null)\r
42             support.exception(t);\r
43         else\r
44             super.exception(t);\r
45     }\r
46 \r
47     public void dispose() {\r
48         disposed = true;\r
49     }\r
50 \r
51     @Override\r
52     public boolean isDisposed() {\r
53         boolean d = disposed || (support != null && support.isDisposed());\r
54         return d;\r
55     }\r
56 \r
57     @Override\r
58     public int hashCode() {\r
59         return ObjectUtils.hashCode(support) + 31 * ObjectUtils.hashCode(updateCallback);\r
60     }\r
61 \r
62     @Override\r
63     public boolean equals(Object obj) {\r
64         if (this == obj)\r
65             return true;\r
66         if (obj == null)\r
67             return false;\r
68         if (getClass() != obj.getClass())\r
69             return false;\r
70         PartNameListener other = (PartNameListener) obj;\r
71         return ObjectUtils.objectEquals(support, other.support)\r
72                 && ObjectUtils.objectEquals(updateCallback, other.updateCallback);\r
73     }\r
74 \r
75 }\r