📄 structuredviewer.java
字号:
} /** * Hook for testing. * @param element * @return Widget */ public Widget testFindItem(Object element) { return findItem(element); } /** * Hook for testing. * @param element * @return Widget[] * @since 3.2 */ public Widget[] testFindItems(Object element) { return findItems(element); } /** * Removes all elements from the map. * <p> * This method is internal to the framework; subclassers should not call * this method. * </p> */ protected void unmapAllElements() { if (elementMap != null) { elementMap = newHashtable(CustomHashtable.DEFAULT_CAPACITY); } } /** * Removes the given element from the internal element to widget map. Does * nothing if mapping is disabled. If mapping is enabled, the given element * must be present. * <p> * This method is internal to the framework; subclassers should not call * this method. * </p> * * @param element * the element */ protected void unmapElement(Object element) { if (elementMap != null) { elementMap.remove(element); } } /** * Removes the given association from the internal element to widget map. * Does nothing if mapping is disabled, or if the given element does not map * to the given item. * <p> * This method is internal to the framework; subclassers should not call * this method. * </p> * * @param element * the element * @param item the item to unmap * @since 2.0 */ protected void unmapElement(Object element, Widget item) { // double-check that the element actually maps to the given item before // unmapping it if (elementMap != null) { Object widgetOrWidgets = elementMap.get(element); if (widgetOrWidgets == null) { // item was not mapped, return return; } else if (widgetOrWidgets instanceof Widget) { if (item == widgetOrWidgets) { elementMap.remove(element); } } else { Widget[] widgets = (Widget[]) widgetOrWidgets; int indexOfItem = Arrays.asList(widgets).indexOf(item); if (indexOfItem == -1) { return; } int length = widgets.length; if (indexOfItem == 0) { if(length == 1) { elementMap.remove(element); } else { Widget[] updatedWidgets = new Widget[length - 1]; System.arraycopy(widgets, 1, updatedWidgets, 0, length -1 ); elementMap.put(element, updatedWidgets); } } else { Widget[] updatedWidgets = new Widget[length - 1]; System.arraycopy(widgets, 0, updatedWidgets, 0, indexOfItem); System.arraycopy(widgets, indexOfItem + 1, updatedWidgets, indexOfItem, length - indexOfItem - 1); elementMap.put(element, updatedWidgets); } } } } /** * Updates the given elements' presentation when one or more of their * properties change. Only the given elements are updated. * <p> * This does not handle structural changes (e.g. addition or removal of * elements), and does not update any other related elements (e.g. child * elements). To handle structural changes, use the <code>refresh</code> * methods instead. * </p> * <p> * This should be called when an element has changed in the model, in order * to have the viewer accurately reflect the model. This method only affects * the viewer, not the model. * </p> * <p> * Specifying which properties are affected may allow the viewer to optimize * the update. For example, if the label provider is not affected by changes * to any of these properties, an update may not actually be required. * Specifing <code>properties</code> as <code>null</code> forces a full * update of the given elements. * </p> * <p> * If the viewer has a sorter which is affected by a change to one of the * properties, the elements' positions are updated to maintain the sort * order. * </p> * <p> * If the viewer has a filter which is affected by a change to one of the * properties, elements may appear or disappear if the change affects * whether or not they are filtered out. * </p> * * @param elements * the elements * @param properties * the properties that have changed, or <code>null</code> to * indicate unknown */ public void update(Object[] elements, String[] properties) { for (int i = 0; i < elements.length; ++i) { update(elements[i], properties); } } /** * Updates the given element's presentation when one or more of its * properties changes. Only the given element is updated. * <p> * This does not handle structural changes (e.g. addition or removal of * elements), and does not update any other related elements (e.g. child * elements). To handle structural changes, use the <code>refresh</code> * methods instead. * </p> * <p> * This should be called when an element has changed in the model, in order * to have the viewer accurately reflect the model. This method only affects * the viewer, not the model. * </p> * <p> * Specifying which properties are affected may allow the viewer to optimize * the update. For example, if the label provider is not affected by changes * to any of these properties, an update may not actually be required. * Specifing <code>properties</code> as <code>null</code> forces a full * update of the element. * </p> * <p> * If the viewer has a sorter which is affected by a change to one of the * properties, the element's position is updated to maintain the sort order. * </p> * <p> * If the viewer has a filter which is affected by a change to one of the * properties, the element may appear or disappear if the change affects * whether or not the element is filtered out. * </p> * * @param element * the element * @param properties * the properties that have changed, or <code>null</code> to * indicate unknown */ public void update(Object element, String[] properties) { Assert.isNotNull(element); Widget[] items = findItems(element); for (int i = 0; i < items.length; i++) { internalUpdate(items[i], element, properties); } } /** * Updates the given element's presentation when one or more of its * properties changes. Only the given element is updated. * <p> * EXPERIMENTAL. Not to be used except by JDT. * This method was added to support JDT's explorations * into grouping by working sets, which requires viewers to support multiple * equal elements. See bug 76482 for more details. This support will * likely be removed in Eclipse 3.3 in favour of proper support for * multiple equal elements (which was implemented for AbtractTreeViewer in 3.2). * </p> * @param widget * the widget for the element * @param element * the element * @param properties * the properties that have changed, or <code>null</code> to * indicate unknown */ protected void internalUpdate(Widget widget, Object element, String[] properties) { boolean needsRefilter = false; if (properties != null) { for (int i = 0; i < properties.length; ++i) { needsRefilter = needsRefilter(element, properties[i]); if (needsRefilter) { break; } } } if (needsRefilter) { refresh(); return; } boolean needsUpdate; if (properties == null) { needsUpdate = true; } else { needsUpdate = false; IBaseLabelProvider labelProvider = getLabelProvider(); for (int i = 0; i < properties.length; ++i) { needsUpdate = labelProvider.isLabelProperty(element, properties[i]); if (needsUpdate) { break; } } } if (needsUpdate) { updateItem(widget, element); } } /** * Copies attributes of the given element into the given widget. * <p> * This method is internal to the framework; subclassers should not call * this method. Calls <code>doUpdateItem(widget, element, true)</code>. * </p> * * @param widget * the widget * @param element * the element */ protected final void updateItem(Widget widget, Object element) { SafeRunnable.run(new UpdateItemSafeRunnable(widget, element, true)); } /** * Updates the selection of this viewer. * <p> * This framework method should be called when the selection in the viewer * widget changes. * </p> * <p> * The default implementation of this method notifies all selection change * listeners recorded in an internal state variable. Overriding this method * is generally not required; however, if overriding in a subclass, * <code>super.updateSelection</code> must be invoked. * </p> * * @param selection * the selection, or <code>null</code> if none */ protected void updateSelection(ISelection selection) { SelectionChangedEvent event = new SelectionChangedEvent(this, selection); fireSelectionChanged(event); } /** * Returns whether this structured viewer is configured to use an internal * map to speed up the mapping between elements and SWT items. * <p> * The default implementation of this framework method checks whether the * internal map has been initialized. * </p> * * @return <code>true</code> if the element map is enabled, and * <code>false</code> if disabled */ protected boolean usingElementMap() { return elementMap != null; } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ContentViewer#setLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) */ public void setLabelProvider(IBaseLabelProvider labelProvider) { if (labelProvider instanceof IColorProvider || labelProvider instanceof IFontProvider) { colorAndFontCollector = new ColorAndFontCollectorWithProviders(labelProvider); } else { colorAndFontCollector = new ColorAndFontCollector(); } super.setLabelProvider(labelProvider); } /** * Build a label up for the element using the supplied label provider. * @param updateLabel The ViewerLabel to collect the result in * @param element The element being decorated. */ protected void buildLabel(ViewerLabel updateLabel, Object element){ if (getLabelProvider() instanceof IViewerLabelProvider) { IViewerLabelProvider itemProvider = (IViewerLabelProvider) getLabelProvider(); itemProvider.updateLabel(updateLabel, element); colorAndFontCollector.setUsedDecorators(); if(updateLabel.hasNewBackground()) { colorAndFontCollector.setBackground(updateLabel.getBackground()); } if(updateLabel.hasNewForeground()) { colorAndFontCollector.setForeground(updateLabel.getForeground()); } if(updateLabel.hasNewFont()) { colorAndFontCollector.setFont(updateLabel.getFont()); } return; } if(getLabelProvider() instanceof ILabelProvider){ ILabelProvider labelProvider = (ILabelProvider) getLabelProvider(); updateLabel.setText(labelProvider.getText(element)); updateLabel.setImage(labelProvider.getImage(element)); } } /** * Build a label up for the element using the supplied label provider. * @param updateLabel The ViewerLabel to collect the result in * @param element The element being decorated. * @param labelProvider ILabelProvider the labelProvider for the receiver. */ void buildLabel(ViewerLabel updateLabel, Object element,IViewerLabelProvider labelProvider){ labelProvider.updateLabel(updateLabel, element); colorAndFontCollector.setUsedDecorators(); if(updateLabel.hasNewBackground()) { colorAndFontCollector.setBackground(updateLabel.getBackground()); } if(updateLabel.hasNewForeground()) { colorAndFontCollector.setForeground(updateLabel.getForeground()); } if(updateLabel.hasNewFont()) { colorAndFontCollector.setFont(updateLabel.getFont()); } } /** * Build a label up for the element using the supplied label provider. * @param updateLabel The ViewerLabel to collect the result in * @param elementPath The path of the element being decorated. * @param labelProvider ILabelProvider the labelProvider for the receiver. */ void buildLabel(ViewerLabel updateLabel, TreePath elementPath,ITreePathLabelProvider labelProvider){ labelProvider.updateLabel(updateLabel, elementPath); colorAndFontCollector.setUsedDecorators(); if(updateLabel.hasNewBackground()) { colorAndFontCollector.setBackground(updateLabel.getBackground()); } if(updateLabel.hasNewForeground()) { colorAndFontCollector.setForeground(updateLabel.getForeground()); } if(updateLabel.hasNewFont()) { colorAndFontCollector.setFont(updateLabel.getFont()); } } /** * Build a label up for the element using the supplied label provider. * @param updateLabel The ViewerLabel to collect the result in * @param element The element being decorated. * @param labelProvider ILabelProvider the labelProvider for the receiver. */ void buildLabel(ViewerLabel updateLabel, Object element,ILabelProvider labelProvider){ updateLabel.setText(labelProvider.getText(element)); updateLabel.setImage(labelProvider.getImage(element)); } /** * Get the ColorAndFontCollector for the receiver. * @return ColorAndFontCollector * @since 3.1 */ protected ColorAndFontCollector getColorAndFontCollector() { return colorAndFontCollector; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -