]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/SWTConstantInput.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / SWTConstantInput.java
1 /*******************************************************************************
2  * Copyright (c) 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 import java.util.Collections;
15 import java.util.Map;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.simantics.browsing.ui.common.ColumnKeys;
19 import org.simantics.browsing.ui.common.node.ConstantInput;
20
21 final public class SWTConstantInput extends ConstantInput<ImageDescriptor> {
22         
23         final private static Map<String, ImageDescriptor> NO_IMAGES = Collections.emptyMap(); 
24         
25     public SWTConstantInput(Map<String, String> labels, Map<String, ImageDescriptor> imageDescriptors, int category) {
26                 super(labels, imageDescriptors, category);
27         }
28
29         public static SWTConstantInput create(String label) {
30         return new SWTConstantInput(Collections.singletonMap(ColumnKeys.SINGLE, label), NO_IMAGES, 0);
31     }
32
33         public static SWTConstantInput create(String label, ImageDescriptor descriptor) {
34         return new SWTConstantInput(Collections.singletonMap(ColumnKeys.SINGLE, label), Collections.singletonMap(ColumnKeys.SINGLE, descriptor), 0);
35     }
36
37         @Override
38         public int hashCode() {
39                 return labels.hashCode() + 31 * imageDescriptors.hashCode() + 41 * category;
40         }
41         
42     @Override
43     public boolean equals(Object object) {
44         if (this == object)
45             return true;
46         else if (object == null)
47             return false;
48         else if (SWTConstantInput.class != object.getClass())
49             return false;
50         SWTConstantInput r = (SWTConstantInput)object;
51         return r.labels.equals(labels) && r.imageDescriptors.equals(imageDescriptors) && r.category == category;
52     }
53         
54 }