/** * */ package com.topsun.posclient.application; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.jface.action.IContributionItem; public abstract class ContributionItemDescriptor implements IDescriptor { protected String id; protected int index; protected String category; protected boolean visible; protected String text; protected String applicationId; protected boolean defaultItem; public String getApplicationId() { return applicationId; } void setApplicationId(String applicationId) { this.applicationId = applicationId; } void setId(String id) { this.id = id; } public String getId() { return id; } void setIndex(int index) { this.index = index; } public int getIndex() { return index; } void setCategory(String category) { this.category = category; } public String getCategory() { return category; } void setText(String text) { this.text = text; } public String getText() { return text; } void setVisible(boolean visible) { this.visible = visible; } public boolean isVisible() { return this.visible; } void setDefaultItem(boolean defaultItem) { this.defaultItem = defaultItem; } public boolean isDefaultItem() { return this.defaultItem; } public void init(IConfigurationElement element) { setId(element.getAttribute("id")); setIndex(Integer.parseInt(element.getAttribute("index") == null ? "0" : element.getAttribute("index"))); setCategory(element.getAttribute("category")); setText(element.getAttribute("text")); setVisible(Boolean.parseBoolean(element.getAttribute("visible") == null ? "true" : element.getAttribute("visible"))); setDefaultItem(Boolean.parseBoolean(element.getAttribute("defaultItem") == null ? "true" : element.getAttribute("defaultItem"))); setApplicationId(element.getAttribute("applicationId") == null ? "default" : element.getAttribute("applicationId")); } public abstract IContributionItem createItem(); public boolean equals(Object other) { if (other instanceof ContributionItemDescriptor == false) { return false; } ContributionItemDescriptor otherDescriptor = (ContributionItemDescriptor) other; return getCategory().equals(otherDescriptor.getCategory()) && getId().equals(otherDescriptor.getId()); } public int hashCode() { int total = 17; int constant = 37; total = total * constant + (getCategory() != null ? getCategory().hashCode() : 0); total = total * constant + (getId() != null ? getId().hashCode() : 0); return total; } public String toString() { return "{" + getCategory() + ":" + getId() + "}-[" + getApplicationId() + "]"; } }