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