📄 viewlabelprovider.java
字号:
/* * Copyright 2006 Marcel Schoffelmeer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.s10r.manager;import org.eclipse.jface.viewers.ILabelProviderListener;import org.eclipse.jface.viewers.ITableLabelProvider;import org.eclipse.swt.graphics.Image;import org.eclipse.ui.plugin.AbstractUIPlugin;import com.s10r.manager.model.ItemContainer;import com.s10r.manager.model.ItemLabel;import com.s10r.manager.model.ManagerItem;import com.s10r.manager.model.PasswordEntry;import com.s10r.util.DateUtil;/** * The content provider class is responsible for providing objects to the view. * It can wrap existing objects in adapters or simply return objects as-is. * These objects may be sensitive to the current input of the view, or ignore it * and always show the same content (like Task List, for example). */public class ViewLabelProvider implements ITableLabelProvider{ private static final int NAME_COLUMN_IDX = 0; private static final int ID_COLUMN_IDX = 1; private static final int PASSWORD_COLUMN_IDX = 2; private static final int DESCRIPTION_COLUMN_IDX = 3; private static final int USAGE_CNT_COLUMN_IDX = 4; private static final int LAST_USED_COLUMN_IDX = 5; private static final int LAST_UPDATED_IDX = 6; private static final int LAST_UPDATED_ON_SITE_IDX = 7; private static final int URL_IDX = 8; private static final int LABELS_IDX = 9; ItemContainer entries = null; private Image passwordEntryImage; private Image labelImage; public ViewLabelProvider(ItemContainer entries2) { this.entries = entries2; passwordEntryImage = AbstractUIPlugin.imageDescriptorFromPlugin( // Application.PLUGIN_ID, "icons/enum_obj.gif").createImage(); Application.PLUGIN_ID, "icons/key.png").createImage(); labelImage = AbstractUIPlugin.imageDescriptorFromPlugin( Application.PLUGIN_ID, "icons/tag_blue.png").createImage(); } public String getColumnText(Object obj, int index) { ManagerItem mi = (ManagerItem) obj; // generic properties switch (index) { case NAME_COLUMN_IDX: { return mi.getName(); } case DESCRIPTION_COLUMN_IDX: { return mi.getDescription(); } case LAST_UPDATED_IDX: { if (mi.getLastUpdated() != null) { return DateUtil.format(mi.getLastUpdated()); } else { return ""; } } default: { // handled below } } // password properties if (obj instanceof PasswordEntry) { PasswordEntry pe = (PasswordEntry) obj; switch (index) { case ID_COLUMN_IDX: { if (isShowIds()) { return pe.getId(); } else if (pe.getId() != null && pe.getId().length() > 0) { return "****"; } else { return ""; } } case PASSWORD_COLUMN_IDX: { if (pe.getPassword() != null && pe.getPassword().length() > 0) { return "****"; } else { return ""; } } case USAGE_CNT_COLUMN_IDX: { return "" + (pe.getUsageCnt() > 0 ? pe.getUsageCnt() : ""); } case LAST_USED_COLUMN_IDX: { if (pe.getLastUsed() != null) { return DateUtil.format(pe.getLastUsed()); } else { return ""; } } case LAST_UPDATED_ON_SITE_IDX: { return "" + pe.getPasswordAge(); } case URL_IDX: { return pe.getUrl(); } case LABELS_IDX: { return pe.getLabelsString(); } default: { throw new IllegalArgumentException("invalid column index: " + index); } } } return "-"; // NA (labels) } private boolean isShowIds() { // TODO Auto-generated method stub return false; } public Image getColumnImage(Object obj, int index) { if (index == 0) { return getImage(obj); } else { return null; } } /** * For now only returns the password entry image because that's the only * type of element the table can contain. * * @param obj * @return */ public Image getImage(Object obj) { // TODO: remove usage of instanceof usage: see RCP book if (obj instanceof PasswordEntry) { return passwordEntryImage; } else if (obj instanceof ItemLabel) { return labelImage; } else { return null; } } public void addListener(ILabelProviderListener listener) { // TODO Auto-generated method stub } public void dispose() { // TODO Auto-generated method stub } public boolean isLabelProperty(Object element, String property) { // TODO Auto-generated method stub return false; } public void removeListener(ILabelProviderListener listener) { // TODO Auto-generated method stub }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -