file_name
stringlengths 6
86
| file_path
stringlengths 45
249
| content
stringlengths 47
6.26M
| file_size
int64 47
6.26M
| language
stringclasses 1
value | extension
stringclasses 1
value | repo_name
stringclasses 767
values | repo_stars
int64 8
14.4k
| repo_forks
int64 0
1.17k
| repo_open_issues
int64 0
788
| repo_created_at
stringclasses 767
values | repo_pushed_at
stringclasses 767
values |
---|---|---|---|---|---|---|---|---|---|---|---|
NatTable.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/NatTable.java | package net.sourceforge.nattable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import net.sourceforge.nattable.command.DisposeResourcesCommand;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.config.ConfigRegistry;
import net.sourceforge.nattable.config.DefaultNatTableStyleConfiguration;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.config.IConfiguration;
import net.sourceforge.nattable.conflation.EventConflaterChain;
import net.sourceforge.nattable.conflation.VisualChangeEventConflater;
import net.sourceforge.nattable.coordinate.Range;
import net.sourceforge.nattable.edit.ActiveCellEditor;
import net.sourceforge.nattable.edit.InlineCellEditController;
import net.sourceforge.nattable.grid.command.ClientAreaResizeCommand;
import net.sourceforge.nattable.grid.command.InitializeGridCommand;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.ILayerListener;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.layer.event.ILayerEvent;
import net.sourceforge.nattable.layer.event.IVisualChangeEvent;
import net.sourceforge.nattable.layer.stack.DummyGridLayerStack;
import net.sourceforge.nattable.painter.IOverlayPainter;
import net.sourceforge.nattable.painter.layer.ILayerPainter;
import net.sourceforge.nattable.persistence.IPersistable;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.mode.ConfigurableModeEventHandler;
import net.sourceforge.nattable.ui.mode.Mode;
import net.sourceforge.nattable.ui.mode.ModeSupport;
import net.sourceforge.nattable.util.GUIHelper;
import net.sourceforge.nattable.util.IClientAreaProvider;
import net.sourceforge.nattable.viewport.command.RecalculateScrollBarsCommand;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
public class NatTable extends Canvas implements ILayer, PaintListener, IClientAreaProvider, ILayerListener, IPersistable {
public static final int DEFAULT_STYLE_OPTIONS = SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL;
private UiBindingRegistry uiBindingRegistry;
private ModeSupport modeSupport;
private final EventConflaterChain conflaterChain = new EventConflaterChain();
private final List<IOverlayPainter> overlayPainters = new ArrayList<IOverlayPainter>();
private final List<IPersistable> persistables = new LinkedList<IPersistable>();
private ILayer underlyingLayer;
private IConfigRegistry configRegistry;
private final Collection<IConfiguration> configurations = new LinkedList<IConfiguration>();
protected String id = GUIHelper.getSequenceNumber();
private ILayerPainter layerPainter = new NatLayerPainter();
private final boolean autoconfigure;
public NatTable(Composite parent) {
this(parent, DEFAULT_STYLE_OPTIONS);
}
/**
* @param parent widget for the table.
* @param autoconfigure if set to False
* - No auto configuration is done
* - Default settings are <i>not</i> loaded. Configuration(s) have to be manually
* added by invoking addConfiguration(). At the minimum the {@link DefaultNatTableStyleConfiguration}
* must be added for the table to render.
*/
public NatTable(Composite parent, boolean autoconfigure) {
this(parent, DEFAULT_STYLE_OPTIONS, autoconfigure);
}
public NatTable(Composite parent, ILayer layer) {
this(parent, DEFAULT_STYLE_OPTIONS, layer);
}
public NatTable(Composite parent, ILayer layer, boolean autoconfigure) {
this(parent, DEFAULT_STYLE_OPTIONS, layer, autoconfigure);
}
public NatTable(Composite parent, final int style) {
this(parent, style, new DummyGridLayerStack());
}
public NatTable(Composite parent, final int style, boolean autoconfigure) {
this(parent, style, new DummyGridLayerStack(), autoconfigure);
}
public NatTable(final Composite parent, final int style, ILayer layer) {
this(parent, style, layer, true);
}
public NatTable(final Composite parent, final int style, final ILayer layer, boolean autoconfigure) {
super(parent, style);
// Disable scroll bars by default; if a Viewport is available, it will enable the scroll bars
disableScrollBar(getHorizontalBar());
disableScrollBar(getVerticalBar());
initInternalListener();
internalSetLayer(layer);
this.autoconfigure = autoconfigure;
if (autoconfigure) {
configurations.add(new DefaultNatTableStyleConfiguration());
configure();
}
conflaterChain.add(new VisualChangeEventConflater(this));
conflaterChain.start();
}
@Override
public void dispose() {
doCommand(new DisposeResourcesCommand());
conflaterChain.stop();
InlineCellEditController.dispose();
ActiveCellEditor.close();
super.dispose();
}
private void disableScrollBar(ScrollBar scrollBar) {
scrollBar.setMinimum(0);
scrollBar.setMaximum(1);
scrollBar.setThumb(1);
scrollBar.setEnabled(false);
}
public ILayer getLayer() {
return underlyingLayer;
}
public void setLayer(ILayer layer) {
if (autoconfigure) {
throw new IllegalStateException("May only set layer post construction if autoconfigure is turned off");
}
internalSetLayer(layer);
}
private void internalSetLayer(ILayer layer) {
if (layer != null) {
this.underlyingLayer = layer;
underlyingLayer.setClientAreaProvider(new IClientAreaProvider() {
public Rectangle getClientArea() {
if (!isDisposed()) {
return NatTable.this.getClientArea();
}
else return new Rectangle(0,0,0,0);
}
});
underlyingLayer.addLayerListener(this);
}
}
/**
* Adds a configuration to the table.<br/>
*
* Configurations are processed when the {@link #configure()} method is invoked.<br/>
* Each configuration object then has a chance to configure the<br/>
* <ol>
* <li>ILayer</li>
* <li>ConfigRegistry</li>
* <li>UiBindingRegistry</li>
* </ol>
*/
public void addConfiguration(IConfiguration configuration) {
if (autoconfigure) {
throw new IllegalStateException("May only add configurations post construction if autoconfigure is turned off");
}
configurations.add(configuration);
}
/**
* @return {@link IConfigRegistry} used to hold the configuration bindings<br/>
* by Layer, DisplayMode and Config labels.
*/
public IConfigRegistry getConfigRegistry() {
if (configRegistry == null) {
configRegistry = new ConfigRegistry();
}
return configRegistry;
}
public void setConfigRegistry(IConfigRegistry configRegistry) {
if (autoconfigure) {
throw new IllegalStateException("May only set config registry post construction if autoconfigure is turned off");
}
this.configRegistry = configRegistry;
}
/**
* @return Registry holding all the UIBindings contributed by the underlying layers
*/
public UiBindingRegistry getUiBindingRegistry() {
if (uiBindingRegistry == null) {
uiBindingRegistry = new UiBindingRegistry(this);
}
return uiBindingRegistry;
}
public void setUiBindingRegistry(UiBindingRegistry uiBindingRegistry) {
if (autoconfigure) {
throw new IllegalStateException("May only set UI binding registry post construction if autoconfigure is turned off");
}
this.uiBindingRegistry = uiBindingRegistry;
}
public String getID() {
return id;
}
@Override
protected void checkSubclass() {
}
protected void initInternalListener() {
modeSupport = new ModeSupport(this);
modeSupport.registerModeEventHandler(Mode.NORMAL_MODE, new ConfigurableModeEventHandler(modeSupport, this));
modeSupport.switchMode(Mode.NORMAL_MODE);
addPaintListener(this);
addFocusListener(new FocusListener() {
public void focusLost(final FocusEvent arg0) {
redraw();
}
public void focusGained(final FocusEvent arg0) {
redraw();
}
});
addListener(SWT.Resize, new Listener() {
public void handleEvent(final Event e) {
doCommand(new ClientAreaResizeCommand(NatTable.this));
}
});
}
@Override
public boolean forceFocus() {
return super.forceFocus();
}
// Painting ///////////////////////////////////////////////////////////////
public void addOverlayPainter(IOverlayPainter overlayPainter) {
overlayPainters.add(overlayPainter);
}
public void removeOverlayPainter(IOverlayPainter overlayPainter) {
overlayPainters.remove(overlayPainter);
}
public void paintControl(final PaintEvent event) {
paintNatTable(event);
}
private void paintNatTable(final PaintEvent event) {
getLayerPainter().paintLayer(this, event.gc, 0, 0, new Rectangle(event.x, event.y, event.width, event.height), getConfigRegistry());
}
public ILayerPainter getLayerPainter() {
return layerPainter;
}
public void setLayerPainter(ILayerPainter layerPainter) {
this.layerPainter = layerPainter;
}
/**
* Repaint only a specific column in the grid. This method is optimized so that only the specific column is
* repainted and nothing else.
*
* @param gridColumnPosition column of the grid to repaint
*/
public void repaintColumn(int columnPosition) {
redraw(getStartXOfColumnPosition(columnPosition),
0,
getColumnWidthByPosition(columnPosition),
getHeight(),
true);
}
/**
* Repaint only a specific row in the grid. This method is optimized so that only the specific row is repainted and
* nothing else.
*
* @param gridRowPosition row of the grid to repaint
*/
public void repaintRow(int rowPosition) {
redraw(0,
getStartYOfRowPosition(rowPosition),
getWidth(),
getRowHeightByPosition(rowPosition),
true);
}
public void updateResize() {
updateResize(true);
}
/**
* Update the table screen by re-calculating everything again. It should not
* be called too frequently.
*
* @param redraw
* true to redraw the table
*/
private void updateResize(final boolean redraw) {
if (isDisposed()) {
return;
}
doCommand(new RecalculateScrollBarsCommand());
if (redraw) {
redraw();
}
}
public void configure(ConfigRegistry configRegistry, UiBindingRegistry uiBindingRegistry) {
throw new UnsupportedOperationException("Cannot use this method to configure NatTable. Use no-argument configure() instead.");
}
/**
* Processes all the registered {@link IConfiguration} (s).
* All the underlying layers are walked and given a chance to configure.
* Note: all desired configuration tweaks must be done <i>before</i> this method is invoked.
*/
public void configure() {
if (underlyingLayer == null) {
throw new IllegalStateException("Layer must be set before configure is called");
}
if (underlyingLayer != null) {
underlyingLayer.configure((ConfigRegistry) getConfigRegistry(), uiBindingRegistry);
}
for (IConfiguration configuration : configurations) {
configuration.configureLayer(this);
configuration.configureRegistry(getConfigRegistry());
configuration.configureUiBindings(uiBindingRegistry);
}
// Once everything is initialized and properly configured we will
// now formally initialize the grid
doCommand(new InitializeGridCommand(this));
}
// Events /////////////////////////////////////////////////////////////////
public void handleLayerEvent(ILayerEvent event) {
for (ILayerListener layerListener : listeners) {
layerListener.handleLayerEvent(event);
}
if (event instanceof IVisualChangeEvent) {
conflaterChain.addEvent(event);
}
}
protected Rectangle getPixelRectangleFromPositionRectangle(Rectangle positionRectangle){
int positionRectWidthInPixels = 0;
int positionRectHeightInPixels = 0;
Rectangle pixelRectangle = new Rectangle(0,0,0,0);
for (int i = positionRectangle.x; i < (positionRectangle.x + positionRectangle.width); i++) {
positionRectWidthInPixels += getColumnWidthByPosition(i);
}
for (int i = positionRectangle.y; i < (positionRectangle.y + positionRectangle.height); i++) {
positionRectHeightInPixels += getRowHeightByPosition(i);
}
pixelRectangle.x = getStartXOfColumnPosition(positionRectangle.x);
pixelRectangle.y = getStartYOfRowPosition(positionRectangle.y);
pixelRectangle.width = positionRectWidthInPixels;
pixelRectangle.height = positionRectHeightInPixels;
return pixelRectangle;
}
// ILayer /////////////////////////////////////////////////////////////////
// Persistence
/**
* Save the state of the table to the properties object.
* {@link ILayer#saveState(String, Properties)} is invoked on all the underlying layers.
* This properties object will be populated with the settings of all underlying layers
* and any {@link IPersistable} registered with those layers.
*/
public void saveState(String prefix, Properties properties) {
underlyingLayer.saveState(prefix, properties);
}
/**
* Restore the state of the underlying layers from the values in the properties object.
* @see #saveState(String, Properties)
*/
public void loadState(String prefix, Properties properties) {
underlyingLayer.loadState(prefix, properties);
}
/**
* @see ILayer#registerPersistable(IPersistable)
*/
public void registerPersistable(IPersistable persistable) {
persistables.add(persistable);
}
public void unregisterPersistable(IPersistable persistable) {
persistables.remove(persistable);
}
// Command
public boolean doCommand(ILayerCommand command) {
return underlyingLayer.doCommand(command);
}
// Events
private final List<ILayerListener> listeners = new ArrayList<ILayerListener>();
public void fireLayerEvent(ILayerEvent event) {
underlyingLayer.fireLayerEvent(event);
}
public void addLayerListener(ILayerListener listener) {
listeners.add(listener);
}
public void removeLayerListener(ILayerListener listener) {
listeners.remove(listener);
}
// Columns
public int getColumnCount() {
return underlyingLayer.getColumnCount();
}
public int getPreferredColumnCount() {
return underlyingLayer.getPreferredColumnCount();
}
public int getColumnIndexByPosition(int columnPosition) {
return underlyingLayer.getColumnIndexByPosition(columnPosition);
}
public int localToUnderlyingColumnPosition(int localColumnPosition) {
return localColumnPosition;
}
public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) {
if (sourceUnderlyingLayer != underlyingLayer) {
return -1;
}
return underlyingColumnPosition;
}
public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) {
if (sourceUnderlyingLayer != underlyingLayer) {
return null;
}
return underlyingColumnPositionRanges;
}
// Width
public int getWidth() {
return underlyingLayer.getWidth();
}
public int getPreferredWidth() {
return underlyingLayer.getPreferredWidth();
}
public int getColumnWidthByPosition(int columnPosition) {
return underlyingLayer.getColumnWidthByPosition(columnPosition);
}
// Column resize
public boolean isColumnPositionResizable(int columnPosition) {
return underlyingLayer.isColumnPositionResizable(columnPosition);
}
// X
public int getColumnPositionByX(int x) {
return underlyingLayer.getColumnPositionByX(x);
}
public int getStartXOfColumnPosition(int columnPosition) {
return underlyingLayer.getStartXOfColumnPosition(columnPosition);
}
// Underlying
public Collection<ILayer> getUnderlyingLayersByColumnPosition(int columnPosition) {
Collection<ILayer> underlyingLayers = new HashSet<ILayer>();
underlyingLayers.add(underlyingLayer);
return underlyingLayers;
}
// Rows
public int getRowCount() {
return underlyingLayer.getRowCount();
}
public int getPreferredRowCount() {
return underlyingLayer.getPreferredRowCount();
}
public int getRowIndexByPosition(int rowPosition) {
return underlyingLayer.getRowIndexByPosition(rowPosition);
}
public int localToUnderlyingRowPosition(int localRowPosition) {
return localRowPosition;
}
public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition) {
if (sourceUnderlyingLayer != underlyingLayer) {
return -1;
}
return underlyingRowPosition;
}
public Collection<Range> underlyingToLocalRowPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingRowPositionRanges) {
if (sourceUnderlyingLayer != underlyingLayer) {
return null;
}
return underlyingRowPositionRanges;
}
// Height
public int getHeight() {
return underlyingLayer.getHeight();
}
public int getPreferredHeight() {
return underlyingLayer.getPreferredHeight();
}
public int getRowHeightByPosition(int rowPosition) {
return underlyingLayer.getRowHeightByPosition(rowPosition);
}
// Row resize
public boolean isRowPositionResizable(int rowPosition) {
return underlyingLayer.isRowPositionResizable(rowPosition);
}
// Y
public int getRowPositionByY(int y) {
return underlyingLayer.getRowPositionByY(y);
}
public int getStartYOfRowPosition(int rowPosition) {
return underlyingLayer.getStartYOfRowPosition(rowPosition);
}
// Underlying
public Collection<ILayer> getUnderlyingLayersByRowPosition(int rowPosition) {
Collection<ILayer> underlyingLayers = new HashSet<ILayer>();
underlyingLayers.add(underlyingLayer);
return underlyingLayers;
}
// Cell features
public LayerCell getCellByPosition(int columnPosition, int rowPosition) {
return underlyingLayer.getCellByPosition(columnPosition, rowPosition);
}
public Rectangle getBoundsByPosition(int columnPosition, int rowPosition) {
return underlyingLayer.getBoundsByPosition(columnPosition, rowPosition);
}
public String getDisplayModeByPosition(int columnPosition, int rowPosition) {
return underlyingLayer.getDisplayModeByPosition(columnPosition, rowPosition);
}
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
return underlyingLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
}
public Object getDataValueByPosition(int columnPosition, int rowPosition) {
return underlyingLayer.getDataValueByPosition(columnPosition, rowPosition);
}
// IRegionResolver
public LabelStack getRegionLabelsByXY(int x, int y) {
return underlyingLayer.getRegionLabelsByXY(x, y);
}
public class NatLayerPainter implements ILayerPainter {
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configRegistry) {
try {
gc.setForeground(getForeground());
gc.setBackground(getBackground());
// Clean Background
gc.fillRectangle(rectangle);
ILayerPainter layerPainter = underlyingLayer.getLayerPainter();
layerPainter.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry);
// draw overlays
for (IOverlayPainter overlayPainter : overlayPainters) {
overlayPainter.paintOverlay(gc, NatTable.this);
}
} catch (Exception e) {
e.printStackTrace(System.err);
System.err.println("Error while painting table: " + e.getMessage());
}
}
public Rectangle adjustCellBounds(Rectangle cellBounds) {
ILayerPainter layerPainter = underlyingLayer.getLayerPainter();
return layerPainter.adjustCellBounds(cellBounds);
}
}
public ILayer getUnderlyingLayerByPosition(int columnPosition, int rowPosition) {
return underlyingLayer;
}
public IClientAreaProvider getClientAreaProvider() {
return this;
}
public void setClientAreaProvider(IClientAreaProvider clientAreaProvider) {
throw new UnsupportedOperationException("Cannot set an area provider.");
}
} | 20,863 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PositionUtil.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/coordinate/PositionUtil.java | package net.sourceforge.nattable.coordinate;
import static net.sourceforge.nattable.util.ObjectUtils.isNotEmpty;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class PositionUtil {
/**
* Finds contiguous numbers in a group of numbers.
* @see ColumnChooserDialogTest#getGroupedByContiguous()
*/
public static List<List<Integer>> getGroupedByContiguous(Collection<Integer> numberCollection) {
List<Integer> numbers = new ArrayList<Integer>(numberCollection);
Collections.sort(numbers);
List<Integer> contiguous = new ArrayList<Integer>();
List<List<Integer>> grouped = new ArrayList<List<Integer>>();
for(int i = 0; i < numbers.size()-1; i++) {
if(numbers.get(i).intValue()+1 != numbers.get(i+1).intValue()){
contiguous.add(numbers.get(i));
grouped.add(contiguous);
contiguous = new ArrayList<Integer>();
} else {
contiguous.add(numbers.get(i));
}
}
if(isNotEmpty(numbers)){
contiguous.add(numbers.get(numbers.size()-1));
}
grouped.add(contiguous);
return grouped;
}
/**
* Creates {@link Range}s out of list of numbers.<br/>
* The contiguous numbers are grouped together in Ranges.<br/>
*
* Example: 0, 1, 2, 4, 5, 6 will return [[Range(0 - 3)][Range(4 - 7)]]<br/>
* The last number in the Range is not inclusive.
*/
public static List<Range> getRanges(Collection<Integer> numbers) {
List<Range> ranges = new ArrayList<Range>();
if(isNotEmpty(numbers)){
for (List<Integer> number : PositionUtil.getGroupedByContiguous(numbers)) {
int start = number.get(0).intValue();
int end = number.get(number.size() - 1).intValue() + 1;
ranges.add(new Range(start, end));
}
}
return ranges;
}
}
| 1,821 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PositionCoordinate.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/coordinate/PositionCoordinate.java | package net.sourceforge.nattable.coordinate;
import net.sourceforge.nattable.layer.ILayer;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
public final class PositionCoordinate {
private ILayer layer;
public int columnPosition;
public int rowPosition;
public PositionCoordinate(ILayer layer, int columnPosition, int rowPosition) {
this.layer = layer;
this.columnPosition = columnPosition;
this.rowPosition = rowPosition;
}
public ILayer getLayer() {
return layer;
}
public int getColumnPosition() {
return columnPosition;
}
public int getRowPosition() {
return rowPosition;
}
public void set(int rowPosition, int columnPosition) {
this.rowPosition = rowPosition;
this.columnPosition = columnPosition;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + layer + ":" + columnPosition + "," + rowPosition + "]";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof PositionCoordinate == false) {
return false;
}
PositionCoordinate that = (PositionCoordinate) obj;
return new EqualsBuilder()
.append(this.layer, that.layer)
.append(this.columnPosition, that.columnPosition)
.append(this.rowPosition, that.rowPosition)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(31, 59)
.append(layer)
.append(columnPosition)
.append(rowPosition)
.toHashCode();
}
}
| 1,627 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
Range.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/coordinate/Range.java | package net.sourceforge.nattable.coordinate;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.builder.HashCodeBuilder;
/**
* Represents an Range of numbers.
* Example a Range of selected rows: 1 - 100
* Ranges are inclusive of their start value and not inclusive of their end value, i.e. start <= x < end
*/
public class Range {
public int start = 0;
public int end = 0;
public Range(int start, int end) {
this.start = start;
this.end = end;
}
public int size() {
return end - start;
}
/**
* @return TRUE if the range contains the given row position
*/
public boolean contains(int position) {
return position >= start && position < end;
}
public boolean overlap(Range range) {
return this.contains(range.start);
}
public Set<Integer> getMembers() {
Set<Integer> members = new HashSet<Integer>();
for (int i = start; i < end; i++) {
members.add(Integer.valueOf(i));
}
return members;
}
@Override
public String toString() {
return "Range[" + start + "," + end + "]";
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Range)) {
return false;
}
Range range2 = (Range) obj;
return (start == range2.start) && (end == range2.end);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
public static void sortByStart(List<Range> ranges) {
Collections.sort(ranges, new Comparator<Range>() {
public int compare(Range range1, Range range2) {
return Integer.valueOf(range1.start).compareTo(
Integer.valueOf(range2.start));
}
});
}
}
| 1,767 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
RowPositionCoordinate.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/coordinate/RowPositionCoordinate.java | package net.sourceforge.nattable.coordinate;
import net.sourceforge.nattable.layer.ILayer;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
public final class RowPositionCoordinate {
private ILayer layer;
public int rowPosition;
public RowPositionCoordinate(ILayer layer, int rowPosition) {
this.layer = layer;
this.rowPosition = rowPosition;
}
public ILayer getLayer() {
return layer;
}
public int getRowPosition() {
return rowPosition;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + layer + ":" + rowPosition + "]";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof RowPositionCoordinate == false) {
return false;
}
RowPositionCoordinate that = (RowPositionCoordinate) obj;
return new EqualsBuilder()
.append(this.layer, that.layer)
.append(this.rowPosition, that.rowPosition)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(647, 579)
.append(layer)
.append(rowPosition)
.toHashCode();
}
}
| 1,221 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnPositionCoordinate.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/coordinate/ColumnPositionCoordinate.java | package net.sourceforge.nattable.coordinate;
import net.sourceforge.nattable.layer.ILayer;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
public final class ColumnPositionCoordinate {
private ILayer layer;
public int columnPosition;
public ColumnPositionCoordinate(ILayer layer, int columnPosition) {
this.layer = layer;
this.columnPosition = columnPosition;
}
public ILayer getLayer() {
return layer;
}
public int getColumnPosition() {
return columnPosition;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + layer + ":" + columnPosition + "]";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ColumnPositionCoordinate == false) {
return false;
}
ColumnPositionCoordinate that = (ColumnPositionCoordinate) obj;
return new EqualsBuilder()
.append(this.layer, that.layer)
.append(this.columnPosition, that.columnPosition)
.isEquals();
}
@Override
public int hashCode() {
return new HashCodeBuilder(133, 95)
.append(layer)
.append(columnPosition)
.toHashCode();
}
}
| 1,274 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IndexCoordinate.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/coordinate/IndexCoordinate.java | package net.sourceforge.nattable.coordinate;
public final class IndexCoordinate {
public final int columnIndex;
public final int rowIndex;
public IndexCoordinate(int columnIndex, int rowIndex) {
this.columnIndex = columnIndex;
this.rowIndex = rowIndex;
}
public int getColumnIndex() {
return columnIndex;
}
public int getRowIndex() {
return rowIndex;
}
@Override
public String toString() {
return getClass().getSimpleName() + "[" + columnIndex + "," + rowIndex + "]";
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof IndexCoordinate == false) {
return false;
}
IndexCoordinate that = (IndexCoordinate) obj;
return this.getColumnIndex() == that.getColumnIndex()
&& this.getRowIndex() == that.getRowIndex();
}
@Override
public int hashCode() {
int hash = 95;
hash = 35 * hash + getColumnIndex();
hash = 35 * hash + getRowIndex() + 87;
return hash;
}
}
| 1,029 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IColumnIdAccessor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IColumnIdAccessor.java | package net.sourceforge.nattable.data;
/**
* Maps between column indexes and id(s).
* A column id is a unique identifier for a column.
*/
public interface IColumnIdAccessor {
public String getColumnId(int columnIndex);
public int getColumnIndex(String columnId);
}
| 288 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ISpanningDataProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/ISpanningDataProvider.java | package net.sourceforge.nattable.data;
import net.sourceforge.nattable.layer.cell.DataCell;
public interface ISpanningDataProvider extends IDataProvider {
public DataCell getCellByPosition(int columnPosition, int rowPosition);
}
| 244 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ReflectiveColumnPropertyAccessor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/ReflectiveColumnPropertyAccessor.java | package net.sourceforge.nattable.data;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Convenience class which uses java reflection to get/set property names
* from the row bean. It looks for getter methods for reading and setter
* methods for writing according to the Java conventions.
*
* @param <R> type of the row object/bean
*/
public class ReflectiveColumnPropertyAccessor<R> implements IColumnPropertyAccessor<R> {
private final List<String> propertyNames;
private Map<String, PropertyDescriptor> propertyDescriptorMap;
/**
* @param propertyNames of the members of the row bean
*/
public ReflectiveColumnPropertyAccessor(String[] propertyNames) {
this.propertyNames = Arrays.asList(propertyNames);
}
public int getColumnCount() {
return propertyNames.size();
}
public Object getDataValue(R rowObj, int columnIndex) {
try {
PropertyDescriptor propertyDesc = getPropertyDescriptor(rowObj, columnIndex);
Method readMethod = propertyDesc.getReadMethod();
return readMethod.invoke(rowObj);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
public void setDataValue(R rowObj, int columnIndex, Object newValue) {
try {
PropertyDescriptor propertyDesc = getPropertyDescriptor(rowObj, columnIndex);
Method writeMethod = propertyDesc.getWriteMethod();
if(writeMethod == null) {
throw new RuntimeException(
"Setter method not found in backing bean for value at column index: " + columnIndex);
}
writeMethod.invoke(rowObj, newValue);
} catch (IllegalArgumentException ex){
System.err.println(
"Data the type being set does not match the data type of the setter method in the backing bean");
} catch (Exception e) {
e.printStackTrace(System.err);
throw new RuntimeException("Error while setting data value");
}
};
public String getColumnProperty(int columnIndex) {
return propertyNames.get(columnIndex);
}
public int getColumnIndex(String propertyName) {
return propertyNames.indexOf(propertyName);
}
private PropertyDescriptor getPropertyDescriptor(R rowObj, int columnIndex) throws IntrospectionException {
if (propertyDescriptorMap == null) {
propertyDescriptorMap = new HashMap<String, PropertyDescriptor>();
PropertyDescriptor[] propertyDescriptors = Introspector.getBeanInfo(rowObj.getClass()).getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
propertyDescriptorMap.put(propertyDescriptor.getName(), propertyDescriptor);
}
}
final String propertyName = propertyNames.get(columnIndex);
return propertyDescriptorMap.get(propertyName);
}
}
| 2,936 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ListDataProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/ListDataProvider.java | package net.sourceforge.nattable.data;
import java.util.List;
/**
* Enables the use of a {@link List} containing POJO(s) as a backing data source.
*
* By default a bean at position 'X' in the list is displayed in
* row 'X' in the table. The properties of the bean are used to
* populate the columns. A {@link IColumnPropertyResolver} is used to
* retrieve column data from the bean properties.
*
* @param <T> type of the Objects in the backing list.
* @see IColumnPropertyResolver
*/
public class ListDataProvider<T> implements IRowDataProvider<T> {
protected List<T> list;
protected IColumnAccessor<T> columnAccessor;
public ListDataProvider(List<T> list, IColumnAccessor<T> columnAccessor) {
this.list = list;
this.columnAccessor = columnAccessor;
}
public int getColumnCount() {
return columnAccessor.getColumnCount();
}
public int getRowCount() {
return list.size();
}
public Object getDataValue(int columnIndex, int rowIndex) {
T rowObj = list.get(rowIndex);
return columnAccessor.getDataValue(rowObj, columnIndex);
}
public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
T rowObj = list.get(rowIndex);
columnAccessor.setDataValue(rowObj, columnIndex, newValue);
}
public T getRowObject(int rowIndex) {
return list.get(rowIndex);
}
public int indexOfRowObject(T rowObject) {
return list.indexOf(rowObject);
}
public List<T> getList() {
return list;
}
}
| 1,508 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IRowDataProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IRowDataProvider.java | package net.sourceforge.nattable.data;
public interface IRowDataProvider<T> extends IDataProvider {
public T getRowObject(int rowIndex);
public int indexOfRowObject(T rowObject);
}
| 198 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IDataProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IDataProvider.java | package net.sourceforge.nattable.data;
import net.sourceforge.nattable.layer.DataLayer;
/**
* Provide data to the table.
*
* @see DataLayer
* @see ListDataProvider
*/
public interface IDataProvider {
/**
* Gets the value at the given column and row index.
*
* @param columnIndex
* @param rowIndex
* @return the data value associated with the specified cell
*/
public Object getDataValue(int columnIndex, int rowIndex);
/**
* Sets the value at the given column and row index. Optional operation. Should throw UnsupportedOperationException
* if this operation is not supported.
*
* @param columnIndex
* @param rowIndex
* @param newValue
*/
public void setDataValue(int columnIndex, int rowIndex, Object newValue);
public int getColumnCount();
public int getRowCount();
}
| 849 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IColumnPropertyResolver.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IColumnPropertyResolver.java | package net.sourceforge.nattable.data;
/**
* Maps between the column property name in the backing data bean
* and its corresponding column index.
*/
public interface IColumnPropertyResolver {
/**
* @param columnIndex i.e the order of the column in the backing bean
*/
public String getColumnProperty(int columnIndex);
/**
* @param propertyName i.e the name of the column in the backing bean
*/
public int getColumnIndex(String propertyName);
}
| 484 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IRowIdAccessor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IRowIdAccessor.java | package net.sourceforge.nattable.data;
import java.io.Serializable;
public interface IRowIdAccessor<R> {
public Serializable getRowId(R rowObject);
}
| 164 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IColumnPropertyAccessor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IColumnPropertyAccessor.java | package net.sourceforge.nattable.data;
public interface IColumnPropertyAccessor<T> extends IColumnAccessor<T>, IColumnPropertyResolver {
}
| 141 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IColumnAccessor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/IColumnAccessor.java | package net.sourceforge.nattable.data;
/**
* Maps the properties from the row object to the corresponding columns.
* @param <T> type of the bean used as a row object
*/
public interface IColumnAccessor<T> {
public Object getDataValue(T rowObject, int columnIndex);
public void setDataValue(T rowObject, int columnIndex, Object newValue);
public int getColumnCount();
}
| 384 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultDataValidator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/validate/DefaultDataValidator.java | package net.sourceforge.nattable.data.validate;
public class DefaultDataValidator implements IDataValidator {
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
return true;
}
}
| 219 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultNumericDataValidator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/validate/DefaultNumericDataValidator.java | package net.sourceforge.nattable.data.validate;
public class DefaultNumericDataValidator implements IDataValidator {
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
try {
new Double(newValue.toString());
} catch (Exception e) {
return false;
}
return true;
}
}
| 322 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IDataValidator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/validate/IDataValidator.java | package net.sourceforge.nattable.data.validate;
import net.sourceforge.nattable.data.IDataProvider;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.edit.editor.TextCellEditor;
public interface IDataValidator {
/**
*
* @param columnIndex Index of the colunm being validated
* @param rowIndex Index of the row being validated
* @param newValue Value entered through the edit control text box, combo box etc.
* Note: In case of the {@link TextCellEditor} the text typed in by the user
* will be converted to the canonical value using the {@link IDisplayConverter}
* before it hits this method
*
* @see IDataProvider#getDataValue(int, int)
*
* @return true is newValue is valid. False otherwise.
*/
public boolean validate(int columnIndex, int rowIndex, Object newValue);
public static final IDataValidator ALWAYS_VALID = new IDataValidator() {
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
return true;
}
};
public static final IDataValidator NEVER_VALID = new IDataValidator() {
public boolean validate(int columnIndex, int rowIndex, Object newValue) {
return false;
}
};
}
| 1,243 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
PercentageDisplayConverter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/convert/PercentageDisplayConverter.java | package net.sourceforge.nattable.data.convert;
public class PercentageDisplayConverter implements IDisplayConverter {
public Object canonicalToDisplayValue(Object canonicalValue) {
double percentageValue = ((Double) canonicalValue).doubleValue();
int displayInt = (int) (percentageValue * 100);
return String.valueOf(displayInt) + "%";
}
public Object displayToCanonicalValue(Object displayValue) {
String displayString = (String) displayValue;
displayString = displayString.trim();
if (displayString.endsWith("%")) {
displayString = displayString.substring(0, displayString.length() - 1);
}
displayString = displayString.trim();
int displayInt = Integer.valueOf(displayString).intValue();
double percentageValue = (double) displayInt / 100;
return Double.valueOf(percentageValue);
}
}
| 820 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IDisplayConverter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/convert/IDisplayConverter.java | package net.sourceforge.nattable.data.convert;
/**
* Converts between two different data representations.
*
* The normal data representation is known as the <i>canonical representation</i>
* The representation displayed on the UI is called the <i>display representation</i>.
*
* For example, the canonical representation might be a Date object,
* whereas the target representation could be a formatted String.
*/
public interface IDisplayConverter {
/**
* Convert backing data value -> value to be displayed<br/>
* Typically converted to a String for display.
*/
public Object canonicalToDisplayValue(Object canonicalValue);
/**
* Convert from display value -> value in the backing data structure<br/>
* NOTE: The type the display value is converted to <i>must</i> match the type
* in the setter of the backing bean/row object
*/
public Object displayToCanonicalValue(Object displayValue);
}
| 949 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultDisplayConverter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/convert/DefaultDisplayConverter.java | package net.sourceforge.nattable.data.convert;
public class DefaultDisplayConverter implements IDisplayConverter {
public Object canonicalToDisplayValue(Object sourceValue) {
return sourceValue != null ? sourceValue.toString() : "";
}
public Object displayToCanonicalValue(Object destinationValue) {
if (destinationValue == null || destinationValue.toString().length() == 0){
return null;
} else {
return destinationValue.toString();
}
}
}
| 479 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultDateDisplayConverter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/convert/DefaultDateDisplayConverter.java | package net.sourceforge.nattable.data.convert;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import net.sourceforge.nattable.util.ObjectUtils;
/**
* Converts a java.util.Date object to a given format and vice versa
*/
public class DefaultDateDisplayConverter implements IDisplayConverter {
private DateFormat dateFormat;
/**
* @param dateFormat as specified in {@link SimpleDateFormat}
*/
public DefaultDateDisplayConverter(String dateFormat) {
this.dateFormat = new SimpleDateFormat(dateFormat);
}
/**
* Convert {@link Date} to {@link String} using the default format from {@link SimpleDateFormat}
*/
public DefaultDateDisplayConverter() {
this.dateFormat = new SimpleDateFormat();
}
public Object canonicalToDisplayValue(Object canonicalValue) {
try {
if (ObjectUtils.isNotNull(canonicalValue)) {
return dateFormat.format(canonicalValue);
}
} catch (Exception e) {
e.printStackTrace(System.err);
}
return canonicalValue;
}
public Object displayToCanonicalValue(Object displayValue) {
try {
return dateFormat.parse(displayValue.toString());
} catch (Exception e) {
e.printStackTrace(System.err);
}
return displayValue;
}
}
| 1,284 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultBooleanDisplayConverter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/convert/DefaultBooleanDisplayConverter.java | package net.sourceforge.nattable.data.convert;
/**
* Data type converter for a Check Box.
* Assumes that the data value is stored as a boolean.
*/
public class DefaultBooleanDisplayConverter implements IDisplayConverter {
public Object displayToCanonicalValue(Object displayValue) {
return Boolean.valueOf(displayValue.toString());
}
public Object canonicalToDisplayValue(Object canonicalValue) {
if (canonicalValue == null) {
return null;
} else {
return canonicalValue.toString();
}
}
}
| 538 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultDoubleDisplayConverter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/data/convert/DefaultDoubleDisplayConverter.java | package net.sourceforge.nattable.data.convert;
import static net.sourceforge.nattable.util.ObjectUtils.isNotEmpty;
import static net.sourceforge.nattable.util.ObjectUtils.isNotNull;
/**
* Converts the display value to a double and vice versa.
*/
public class DefaultDoubleDisplayConverter implements IDisplayConverter {
public Object canonicalToDisplayValue(Object canonicalValue) {
try {
if (isNotNull(canonicalValue)) {
return canonicalValue.toString();
}
return null;
} catch (Exception e) {
return canonicalValue;
}
}
public Object displayToCanonicalValue(Object displayValue) {
try {
if (isNotNull(displayValue) && isNotEmpty(displayValue.toString())) {
return Double.valueOf(displayValue.toString());
}
return null;
} catch (Exception e) {
return displayValue;
}
}
}
| 859 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ToggleFilterRowCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/filterrow/command/ToggleFilterRowCommand.java | package net.sourceforge.nattable.filterrow.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
public class ToggleFilterRowCommand extends AbstractContextFreeCommand {
}
| 203 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ClearFilterCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/filterrow/command/ClearFilterCommand.java | package net.sourceforge.nattable.filterrow.command;
import net.sourceforge.nattable.command.AbstractColumnCommand;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.layer.ILayer;
public class ClearFilterCommand extends AbstractColumnCommand {
public ClearFilterCommand(ILayer layer, int columnPosition) {
super(layer, columnPosition);
}
public ILayerCommand cloneCommand() {
return new ClearFilterCommand(getLayer(), getColumnPosition());
}
}
| 510 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ClearAllFiltersCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/filterrow/command/ClearAllFiltersCommand.java | package net.sourceforge.nattable.filterrow.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
public class ClearAllFiltersCommand extends AbstractContextFreeCommand {
}
| 203 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnGroupEntry.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/ColumnGroupEntry.java | package net.sourceforge.nattable.columnChooser;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.nattable.columnChooser.gui.ColumnChooserDialog;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.eclipse.swt.widgets.TreeItem;
/**
* Object representation of a ColumnGroup in the SWT tree.<br/>
* NOTE: this is set as the SWT data on the {@link TreeItem}.<br/>
*
* @see ColumnChooserDialog#populateModel
*/
public class ColumnGroupEntry {
private final String label;
private final Integer firstElementPosition;
private final Integer firstElementIndex;
private final boolean isCollapsed;
public ColumnGroupEntry(String label, Integer firstElementPosition, Integer firstElementIndex, boolean isCollapsed) {
super();
this.label = label;
this.firstElementPosition = firstElementPosition;
this.firstElementIndex = firstElementIndex;
this.isCollapsed = isCollapsed;
}
public String getLabel() {
return label;
}
public Integer getFirstElementPosition() {
return firstElementPosition;
}
public Integer getFirstElementIndex() {
return firstElementIndex;
}
public boolean isCollapsed() {
return isCollapsed;
}
public static List<Integer> getColumnGroupEntryPositions(List<ColumnGroupEntry> columnEntries) {
List<Integer> columnGroupEntryPositions = new ArrayList<Integer>();
for (ColumnGroupEntry ColumnGroupEntry : columnEntries) {
columnGroupEntryPositions.add(ColumnGroupEntry.getFirstElementPosition());
}
return columnGroupEntryPositions;
}
@Override
public String toString() {
return "ColumnGroupEntry ("+
"Label: " + label +
", firstElementPosition: " + firstElementPosition +
", firstElementIndex: " + firstElementIndex +
", collapsed: " + isCollapsed + ")";
}
@Override
public boolean equals(Object obj) {
return super.equals(obj);
}
@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}
} | 2,028 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ISelectionTreeListener.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/ISelectionTreeListener.java | package net.sourceforge.nattable.columnChooser;
import java.util.List;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
public interface ISelectionTreeListener {
void itemsSelected(List<ColumnEntry> addedItems);
void itemsRemoved(List<ColumnEntry> removedItems);
/**
* If columns moved are adjacent to each other, they are grouped together.
* @param direction
* @param selectedColumnGroupEntries
*/
void itemsMoved(MoveDirectionEnum direction, List<ColumnGroupEntry> selectedColumnGroupEntries, List<ColumnEntry> movedColumnEntries, List<List<Integer>> fromPositions, List<Integer> toPositions);
void itemsExpanded(ColumnGroupEntry columnGroupEntry);
void itemsCollapsed(ColumnGroupEntry columnGroupEntry);
}
| 783 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnChooserUtils.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/ColumnChooserUtils.java | package net.sourceforge.nattable.columnChooser;
import static net.sourceforge.nattable.util.ObjectUtils.asIntArray;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.nattable.grid.layer.ColumnHeaderLayer;
import net.sourceforge.nattable.hideshow.ColumnHideShowLayer;
import net.sourceforge.nattable.hideshow.command.MultiColumnHideCommand;
import net.sourceforge.nattable.hideshow.command.MultiColumnShowCommand;
import net.sourceforge.nattable.layer.DataLayer;
public class ColumnChooserUtils {
public static final String RENAMED_COLUMN_INDICATOR = "*";
public static void hideColumnEntries(List<ColumnEntry> removedItems, ColumnHideShowLayer hideShowLayer) {
MultiColumnHideCommand hideCommand = new MultiColumnHideCommand(
hideShowLayer, asIntArray(getColumnEntryPositions(removedItems)));
hideShowLayer.doCommand(hideCommand);
}
public static void hideColumnPositions(List<Integer> removedPositions, ColumnHideShowLayer hideShowLayer) {
MultiColumnHideCommand hideCommand = new MultiColumnHideCommand(hideShowLayer, asIntArray(removedPositions));
hideShowLayer.doCommand(hideCommand);
}
public static void showColumnEntries(List<ColumnEntry> addedItems, ColumnHideShowLayer hideShowLayer) {
hideShowLayer.doCommand(new MultiColumnShowCommand(asIntArray(getColumnEntryIndexes(addedItems))));
}
public static void showColumnIndexes(List<Integer> addedColumnIndexes, ColumnHideShowLayer hideShowLayer) {
hideShowLayer.doCommand(new MultiColumnShowCommand(asIntArray(addedColumnIndexes)));
}
public static List<ColumnEntry> getHiddenColumnEntries(ColumnHideShowLayer columnHideShowLayer, ColumnHeaderLayer columnHeaderLayer, DataLayer columnHeaderDataLayer) {
Collection<Integer> hiddenColumnIndexes = columnHideShowLayer.getHiddenColumnIndexes();
ArrayList<ColumnEntry> hiddenColumnEntries= new ArrayList<ColumnEntry>();
for (Integer hiddenColumnIndex : hiddenColumnIndexes) {
String label = getColumnLabel(columnHeaderLayer, columnHeaderDataLayer, hiddenColumnIndex);
ColumnEntry columnEntry = new ColumnEntry(label, hiddenColumnIndex, Integer.valueOf(-1));
hiddenColumnEntries.add(columnEntry);
}
return hiddenColumnEntries;
}
/**
* @return The renamed column header name for the given column index (if the column has been renamed),<br/>
* the original column name otherwise.
*/
public static String getColumnLabel(ColumnHeaderLayer columnHeaderLayer, DataLayer columnHeaderDataLayer, Integer columnIndex) {
String label = "";
if (columnHeaderLayer.isColumnRenamed(columnIndex)) {
label = columnHeaderLayer.getRenamedColumnLabelByIndex(columnIndex) + RENAMED_COLUMN_INDICATOR;
} else {
int position = columnHeaderDataLayer.getColumnPositionByIndex(columnIndex.intValue());
label = columnHeaderDataLayer.getDataValueByPosition(position, 0).toString();
}
return label;
}
/**
* Get all visible columns from the selection layer and the corresponding labels in the header
*/
public static List<ColumnEntry> getVisibleColumnsEntries(ColumnHideShowLayer columnHideShowLayer, ColumnHeaderLayer columnHeaderLayer, DataLayer columnHeaderDataLayer) {
int visibleColumnCount = columnHideShowLayer.getColumnCount();
ArrayList<ColumnEntry> visibleColumnEntries= new ArrayList<ColumnEntry>();
for (int i = 0; i < visibleColumnCount; i++) {
int index = columnHideShowLayer.getColumnIndexByPosition(i);
String label = getColumnLabel(columnHeaderLayer, columnHeaderDataLayer, index);
ColumnEntry columnEntry = new ColumnEntry(label, Integer.valueOf(index), Integer.valueOf(i));
visibleColumnEntries.add(columnEntry);
}
return visibleColumnEntries;
}
/**
* Search the collection for the entry with the given index.
*/
public static ColumnEntry find(List<ColumnEntry> entries, int indexToFind) {
for (ColumnEntry columnEntry : entries) {
if(columnEntry.getIndex().equals(indexToFind)){
return columnEntry;
}
}
return null;
}
/**
* Get ColumnEntry positions for the ColumnEntry objects.
*/
public static List<Integer> getColumnEntryPositions(List<ColumnEntry> columnEntries) {
List<Integer> columnEntryPositions = new ArrayList<Integer>();
for (ColumnEntry columnEntry : columnEntries) {
columnEntryPositions.add(columnEntry.getPosition());
}
return columnEntryPositions;
}
/**
* Get ColumnEntry positions for the ColumnEntry objects.
*/
public static List<Integer> getColumnEntryIndexes(List<ColumnEntry> columnEntries) {
List<Integer> columnEntryIndexes = new ArrayList<Integer>();
for (ColumnEntry columnEntry : columnEntries) {
columnEntryIndexes.add(columnEntry.getIndex());
}
return columnEntryIndexes;
}
/**
* @return TRUE if the list contains an entry with the given index
*/
public static boolean containsIndex(List<ColumnEntry> entries, int indexToFind) {
return find(entries, indexToFind) != null;
}
}
| 5,063 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnChooser.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/ColumnChooser.java | package net.sourceforge.nattable.columnChooser;
import java.util.List;
import net.sourceforge.nattable.columnChooser.gui.ColumnChooserDialog;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.grid.layer.ColumnHeaderLayer;
import net.sourceforge.nattable.group.ColumnGroupHeaderLayer;
import net.sourceforge.nattable.group.ColumnGroupModel;
import net.sourceforge.nattable.group.command.ColumnGroupExpandCollapseCommand;
import net.sourceforge.nattable.group.command.ReorderColumnGroupCommand;
import net.sourceforge.nattable.group.command.ReorderColumnsAndGroupsCommand;
import net.sourceforge.nattable.hideshow.ColumnHideShowLayer;
import net.sourceforge.nattable.layer.DataLayer;
import net.sourceforge.nattable.reorder.command.ColumnReorderCommand;
import net.sourceforge.nattable.reorder.command.MultiColumnReorderCommand;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import org.eclipse.swt.widgets.Shell;
public final class ColumnChooser {
private final ColumnChooserDialog columnChooserDialog;
private final ColumnHideShowLayer columnHideShowLayer;
private final DataLayer columnHeaderDataLayer;
private final ColumnHeaderLayer columnHeaderLayer;
private List<ColumnEntry> hiddenColumnEntries;
private List<ColumnEntry> visibleColumnsEntries;
private final ColumnGroupModel columnGroupModel;
private final SelectionLayer selectionLayer;
public ColumnChooser(Shell shell,
SelectionLayer selectionLayer,
ColumnHideShowLayer columnHideShowLayer,
ColumnHeaderLayer columnHeaderLayer,
DataLayer columnHeaderDataLayer,
ColumnGroupHeaderLayer columnGroupHeaderLayer,
ColumnGroupModel columnGroupModel) {
this.selectionLayer = selectionLayer;
this.columnHideShowLayer = columnHideShowLayer;
this.columnHeaderLayer = columnHeaderLayer;
this.columnHeaderDataLayer = columnHeaderDataLayer;
this.columnGroupModel = columnGroupModel;
columnChooserDialog = new ColumnChooserDialog(shell, "Available Columns", "Selected Columns");
}
public void openDialog() {
columnChooserDialog.create();
hiddenColumnEntries = ColumnChooserUtils.getHiddenColumnEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
columnChooserDialog.populateAvailableTree(hiddenColumnEntries, columnGroupModel);
visibleColumnsEntries = ColumnChooserUtils.getVisibleColumnsEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
columnChooserDialog.populateSelectedTree(visibleColumnsEntries, columnGroupModel);
columnChooserDialog.expandAllLeaves();
addListenersOnColumnChooserDialog();
columnChooserDialog.open();
}
private void addListenersOnColumnChooserDialog() {
columnChooserDialog.addListener(new ISelectionTreeListener() {
public void itemsRemoved(List<ColumnEntry> removedItems) {
ColumnChooserUtils.hideColumnEntries(removedItems, columnHideShowLayer);
refreshColumnChooserDialog();
}
public void itemsSelected(List<ColumnEntry> addedItems) {
ColumnChooserUtils.showColumnEntries(addedItems, columnHideShowLayer);
refreshColumnChooserDialog();
}
public void itemsMoved(MoveDirectionEnum direction, List<ColumnGroupEntry> movedColumnGroupEntries, List<ColumnEntry> movedColumnEntries, List<List<Integer>> fromPositions, List<Integer> toPositions) {
moveItems(direction, movedColumnGroupEntries, movedColumnEntries, fromPositions, toPositions);
}
/**
* Fire appropriate commands depending on the events received from the column chooser dialog
* @param direction
* @param movedColumnGroupEntries
* @param movedColumnEntries
* @param fromPositions
* @param toPositions
*/
private void moveItems(MoveDirectionEnum direction, List<ColumnGroupEntry> movedColumnGroupEntries, List<ColumnEntry> movedColumnEntries, List<List<Integer>> fromPositions, List<Integer> toPositions) {
for (int i = 0; i < fromPositions.size(); i++) {
boolean columnGroupMoved = columnGroupMoved(fromPositions.get(i), movedColumnGroupEntries);
boolean multipleColumnsMoved = fromPositions.get(i).size() > 1;
ILayerCommand command = null;
if (!columnGroupMoved && !multipleColumnsMoved) {
int fromPosition = fromPositions.get(i).get(0).intValue();
int toPosition = adjustToPosition(direction, toPositions.get(i).intValue());
command = new ColumnReorderCommand(columnHideShowLayer, fromPosition, toPosition);
} else if(columnGroupMoved && multipleColumnsMoved){
command = new ReorderColumnsAndGroupsCommand(columnHideShowLayer, fromPositions.get(i), adjustToPosition(direction, toPositions.get(i)));
} else if(!columnGroupMoved && multipleColumnsMoved){
command = new MultiColumnReorderCommand(columnHideShowLayer, fromPositions.get(i), adjustToPosition(direction, toPositions.get(i)));
} else if(columnGroupMoved && !multipleColumnsMoved){
command = new ReorderColumnGroupCommand(columnHideShowLayer, fromPositions.get(i).get(0), adjustToPosition(direction, toPositions.get(i)));
}
columnHideShowLayer.doCommand(command);
}
refreshColumnChooserDialog();
columnChooserDialog.setSelectionIncludingNested(ColumnChooserUtils.getColumnEntryIndexes(movedColumnEntries));
}
private int adjustToPosition(MoveDirectionEnum direction, Integer toColumnPosition) {
if (MoveDirectionEnum.DOWN == direction) {
return toColumnPosition + 1;
} else {
return toColumnPosition;
}
}
private boolean columnGroupMoved(List<Integer> fromPositions, List<ColumnGroupEntry> movedColumnGroupEntries) {
for (ColumnGroupEntry columnGroupEntry : movedColumnGroupEntries) {
if(fromPositions.contains(columnGroupEntry.getFirstElementPosition())) return true;
}
return false;
}
public void itemsCollapsed(ColumnGroupEntry columnGroupEntry) {
int index = columnGroupEntry.getFirstElementIndex().intValue();
int position = selectionLayer.getColumnPositionByIndex(index);
selectionLayer.doCommand(new ColumnGroupExpandCollapseCommand(selectionLayer, position));
}
public void itemsExpanded(ColumnGroupEntry columnGroupEntry) {
int index = columnGroupEntry.getFirstElementIndex().intValue();
int position = selectionLayer.getColumnPositionByIndex(index);
selectionLayer.doCommand(new ColumnGroupExpandCollapseCommand(selectionLayer, position));
}
});
}
private void refreshColumnChooserDialog() {
hiddenColumnEntries = ColumnChooserUtils.getHiddenColumnEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
visibleColumnsEntries = ColumnChooserUtils.getVisibleColumnsEntries(columnHideShowLayer, columnHeaderLayer, columnHeaderDataLayer);
columnChooserDialog.removeAllLeaves();
columnChooserDialog.populateSelectedTree(visibleColumnsEntries, columnGroupModel);
columnChooserDialog.populateAvailableTree(hiddenColumnEntries, columnGroupModel);
columnChooserDialog.expandAllLeaves();
}
}
| 7,186 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnEntry.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/ColumnEntry.java | package net.sourceforge.nattable.columnChooser;
/**
* Object representation of a NatTable Column. <br/>
* This is used in the Column chooser dialogs as a mechanism of preserving
* meta data on the columns in the dialog.
*
* @see ColumnChooserUtils
*/
public class ColumnEntry {
private final String label;
private final Integer index;
private Integer position;
public ColumnEntry(String label, Integer index, Integer position) {
this.label = label;
this.index = index;
this.position = position;
}
@Override
public String toString() {
return label != null ? label : "No Label";
}
public Integer getPosition() {
return position;
}
public void setPosition(Integer position) {
this.position = position;
}
public Integer getIndex() {
return index;
}
public String getLabel() {
return toString();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof ColumnEntry) {
ColumnEntry that = (ColumnEntry) obj;
return index.intValue() == that.index.intValue();
}
return super.equals(obj);
}
@Override
public int hashCode() {
return index.hashCode();
}
} | 1,184 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnChooserDialog.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/gui/ColumnChooserDialog.java | package net.sourceforge.nattable.columnChooser.gui;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.sourceforge.nattable.columnChooser.ColumnChooserUtils;
import net.sourceforge.nattable.columnChooser.ColumnEntry;
import net.sourceforge.nattable.columnChooser.ColumnGroupEntry;
import net.sourceforge.nattable.columnChooser.ISelectionTreeListener;
import net.sourceforge.nattable.coordinate.PositionUtil;
import net.sourceforge.nattable.group.ColumnGroupModel;
import net.sourceforge.nattable.group.ColumnGroupUtils;
import net.sourceforge.nattable.selection.SelectionLayer.MoveDirectionEnum;
import net.sourceforge.nattable.util.ArrayUtil;
import net.sourceforge.nattable.util.GUIHelper;
import net.sourceforge.nattable.util.ObjectUtils;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.TreeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
public class ColumnChooserDialog extends AbstractColumnChooserDialog {
private Tree availableTree;
private Tree selectedTree;
private final String selectedLabel;
private final String availableLabel;
private ColumnGroupModel columnGroupModel;
public ColumnChooserDialog(Shell parentShell, String availableLabel, String selectedLabel) {
super(parentShell);
this.availableLabel = availableLabel;
this.selectedLabel = selectedLabel;
}
@Override
public void populateDialogArea(Composite parent) {
GridDataFactory.fillDefaults().grab(true, true).applyTo(parent);
parent.setLayout(new GridLayout(4, false));
createLabels(parent, availableLabel, selectedLabel);
availableTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
GridData gridData = GridDataFactory.fillDefaults().grab(true, true).create();
availableTree.setLayoutData(gridData);
availableTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
addSelected();
}
});
availableTree.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
addSelected();
}
});
Composite buttonComposite = new Composite(parent, SWT.NONE);
buttonComposite.setLayout(new GridLayout(1, true));
Button addButton = new Button(buttonComposite, SWT.PUSH);
addButton.setImage(GUIHelper.getImage("arrow_right"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
addButton.setLayoutData(gridData);
addButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
addSelected();
}
});
Button removeButton = new Button(buttonComposite, SWT.PUSH);
removeButton.setImage(GUIHelper.getImage("arrow_left"));
gridData = GridDataFactory.copyData(gridData);
removeButton.setLayoutData(gridData);
removeButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
removeSelected();
}
});
selectedTree = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.Expand);
gridData = GridDataFactory.fillDefaults().grab(true, true).create();
selectedTree.setLayoutData(gridData);
selectedTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
removeSelected();
}
});
selectedTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
boolean controlMask = (e.stateMask & SWT.CONTROL) == SWT.CONTROL;
if (controlMask && e.keyCode == SWT.ARROW_UP) {
moveSelectedUp();
e.doit = false;
} else if (controlMask && e.keyCode == SWT.ARROW_DOWN) {
moveSelectedDown();
e.doit = false;
}
}
@Override
public void keyReleased(KeyEvent e) {
if (e.character == ' ')
removeSelected();
}
});
selectedTree.addTreeListener(new TreeListener(){
public void treeCollapsed(TreeEvent event) {
selectedTreeCollapsed(event);
}
public void treeExpanded(TreeEvent event) {
selectedTreeExpanded(event);
}
});
selectedTree.addSelectionListener(new SelectionListener(){
public void widgetDefaultSelected(SelectionEvent event) {
widgetSelected(event);
}
public void widgetSelected(SelectionEvent event) {
toggleColumnGroupSelection((TreeItem) event.item);
}
});
Composite upDownbuttonComposite = new Composite(parent, SWT.NONE);
upDownbuttonComposite.setLayout(new GridLayout(1, true));
Button upButton = new Button(upDownbuttonComposite, SWT.PUSH);
upButton.setImage(GUIHelper.getImage("arrow_up"));
gridData = GridDataFactory.fillDefaults().grab(false, true).align(SWT.CENTER, SWT.CENTER).create();
upButton.setLayoutData(gridData);
upButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
moveSelectedUp();
}
});
Button downButton = new Button(upDownbuttonComposite, SWT.PUSH);
downButton.setImage(GUIHelper.getImage("arrow_down"));
gridData = GridDataFactory.copyData(gridData);
downButton.setLayoutData(gridData);
downButton.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
public void widgetSelected(SelectionEvent e) {
moveSelectedDown();
}
});
}
protected final void fireItemsSelected(List<ColumnEntry> addedItems) {
for (Object listener : listeners.getListeners()) {
((ISelectionTreeListener) listener).itemsSelected(addedItems);
}
}
protected final void fireItemsRemoved(List<ColumnEntry> removedItems) {
for (Object listener : listeners.getListeners()) {
((ISelectionTreeListener) listener).itemsRemoved(removedItems);
}
}
protected final void fireItemsMoved(MoveDirectionEnum direction, List<ColumnGroupEntry> selectedColumnGroupEntries, List<ColumnEntry> selectedColumnEntries, List<List<Integer>> fromPositions, List<Integer> toPositions) {
for (Object listener : listeners.getListeners()) {
((ISelectionTreeListener) listener).itemsMoved(direction, selectedColumnGroupEntries, selectedColumnEntries, fromPositions, toPositions);
}
}
private void fireGroupExpanded(ColumnGroupEntry columnGroupEntry) {
for (Object listener : listeners.getListeners()) {
((ISelectionTreeListener) listener).itemsExpanded(columnGroupEntry);
}
}
private void fireGroupCollapsed(ColumnGroupEntry columnGroupEntry) {
for (Object listener : listeners.getListeners()) {
((ISelectionTreeListener) listener).itemsCollapsed(columnGroupEntry);
}
}
public void populateSelectedTree(List<ColumnEntry> columnEntries, ColumnGroupModel columnGroupModel) {
populateModel(selectedTree, columnEntries, columnGroupModel);
}
public void populateAvailableTree(List<ColumnEntry> columnEntries, ColumnGroupModel columnGroupModel) {
populateModel(availableTree, columnEntries, columnGroupModel);
}
/**
* Populates the tree.
* Looks for column group and adds an extra node for the group.
* The column leaves carry a {@link ColumnEntry} object as data.
* The column group leaves carry a {@link ColumnGroupEntry} object as data.
*/
private void populateModel(Tree tree, List<ColumnEntry> columnEntries, ColumnGroupModel columnGroupModel) {
this.columnGroupModel = columnGroupModel;
for (ColumnEntry columnEntry : columnEntries) {
TreeItem treeItem;
int columnEntryIndex = columnEntry.getIndex().intValue();
// Create a node for the column group - if needed
if (columnGroupModel != null && columnGroupModel.isPartOfAGroup(columnEntryIndex)) {
String columnGroupName = columnGroupModel.getColumnGroupNameForIndex(columnEntryIndex);
TreeItem columnGroupTreeItem = getTreeItem(tree, columnGroupName);
if (columnGroupTreeItem == null) {
columnGroupTreeItem = new TreeItem(tree, SWT.NONE);
ColumnGroupEntry columnGroupEntry = new ColumnGroupEntry(
columnGroupName,
columnEntry.getPosition(),
columnEntry.getIndex(),
columnGroupModel.isCollapsed(columnEntryIndex));
columnGroupTreeItem.setData(columnGroupEntry);
columnGroupTreeItem.setText(columnGroupEntry.getLabel());
}
treeItem = new TreeItem(columnGroupTreeItem, SWT.NONE);
} else {
treeItem = new TreeItem(tree, SWT.NONE);
}
treeItem.setText(columnEntry.getLabel());
treeItem.setData(columnEntry);
}
}
/**
* If the tree contains an item with the given label return it
*/
private TreeItem getTreeItem(Tree tree, String label) {
for (TreeItem treeItem : tree.getItems()) {
if (treeItem.getText().equals(label)) {
return treeItem;
}
}
return null;
}
/**
* Get the ColumnEntries from the selected TreeItem(s)
* Includes nested column group entries - if the column group is selected.
* Does not include parent of the nested entries - since that does not denote an actual column
*/
private List<ColumnEntry> getColumnEntriesIncludingNested(TreeItem[] selectedTreeItems) {
List<ColumnEntry> selectedColumnEntries = new ArrayList<ColumnEntry>();
for (int i = 0; i < selectedTreeItems.length; i++) {
// Column Group selected - get all children
if (isColumnGroupLeaf(selectedTreeItems[i])) {
TreeItem[] itemsInGroup = selectedTreeItems[i].getItems();
for (TreeItem itemInGroup : itemsInGroup) {
selectedColumnEntries.add((ColumnEntry) itemInGroup.getData());
}
} else {
// Column
selectedColumnEntries.add(getColumnEntryInLeaf(selectedTreeItems[i]));
}
}
return selectedColumnEntries;
}
private List<ColumnGroupEntry> getSelectedColumnGroupEntries(TreeItem[] selectedTreeItems) {
List<ColumnGroupEntry> selectedColumnGroups = new ArrayList<ColumnGroupEntry>();
for (int i = 0; i < selectedTreeItems.length; i++) {
if (isColumnGroupLeaf(selectedTreeItems[i])) {
selectedColumnGroups.add((ColumnGroupEntry) selectedTreeItems[i].getData());
}
}
return selectedColumnGroups;
}
private List<ColumnEntry> getSelectedColumnEntriesIncludingNested(Tree tree){
return getColumnEntriesIncludingNested(tree.getSelection());
}
private List<ColumnGroupEntry> getSelectedColumnGroupEntries(Tree tree){
return getSelectedColumnGroupEntries(tree.getSelection());
}
// Event handlers
/**
* Add selected items: 'Available tree' --> 'Selected tree' Notify
* listeners.
*/
private void addSelected() {
if (isAnyLeafSelected(availableTree)) {
fireItemsSelected(getSelectedColumnEntriesIncludingNested(availableTree));
}
}
/**
* Add selected items: 'Available tree' <-- 'Selected tree' Notify
* listeners.
*/
private void removeSelected() {
if (isAnyLeafSelected(selectedTree)) {
fireItemsRemoved(getSelectedColumnEntriesIncludingNested(selectedTree));
}
}
private void selectedTreeCollapsed(TreeEvent event) {
TreeItem item = (TreeItem) event.item;
ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) item.getData();
fireGroupCollapsed(columnGroupEntry);
}
private void selectedTreeExpanded(TreeEvent event) {
TreeItem item = (TreeItem) event.item;
ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) item.getData();
fireGroupExpanded(columnGroupEntry);
}
private void toggleColumnGroupSelection(TreeItem treeItem) {
if(isColumnGroupLeaf(treeItem)){
Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(selectedTree.getSelection());
boolean selected = selectedLeaves.contains(treeItem);
if(selected){
selectAllChildren(selectedTree, treeItem);
} else {
unSelectAllChildren(selectedTree, treeItem);
}
}
}
private void selectAllChildren(Tree tree, TreeItem treeItem) {
Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
if(isColumnGroupLeaf(treeItem)){
selectedLeaves.addAll(ArrayUtil.asCollection(treeItem.getItems()));
}
tree.setSelection(selectedLeaves.toArray(new TreeItem[]{}));
tree.showSelection();
}
private void unSelectAllChildren(Tree tree, TreeItem treeItem) {
Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
if(isColumnGroupLeaf(treeItem)){
selectedLeaves.removeAll(ArrayUtil.asCollection(treeItem.getItems()));
}
tree.setSelection(selectedLeaves.toArray(new TreeItem[]{}));
tree.showSelection();
}
/**
* Move columns <i>up</i> in the 'Selected' Tree (Right)
*/
@SuppressWarnings("boxing")
protected void moveSelectedUp() {
if (isAnyLeafSelected(selectedTree)) {
if(!isFirstLeafSelected(selectedTree)){
List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(selectedTree);
List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(selectedTree);
List<Integer> allSelectedPositions = merge(selectedColumnEntries, selectedColumnGroupEntries);
// Group continuous positions. If a column group moves, a bunch of 'from' positions move
// to a single 'to' position
List<List<Integer>> postionsGroupedByContiguous = PositionUtil.getGroupedByContiguous(allSelectedPositions);
List<Integer> toPositions = new ArrayList<Integer>();
//Set destination positions
for (List<Integer> groupedPositions : postionsGroupedByContiguous) {
// Do these contiguous positions contain a column group ?
boolean columnGroupMoved = columnGroupMoved(groupedPositions, selectedColumnGroupEntries);
// If already at first position do not move
int firstPositionInGroup = groupedPositions.get(0);
if (firstPositionInGroup == 0){
return;
}
// Column entry
ColumnEntry columnEntry = getColumnEntryForPosition(selectedTree, firstPositionInGroup);
int columnEntryIndex = columnEntry.getIndex();
// Previous column entry
ColumnEntry previousColumnEntry = getColumnEntryForPosition(selectedTree, firstPositionInGroup - 1);
int previousColumnEntryIndex = previousColumnEntry.getIndex();
if (columnGroupMoved) {
// If the previous entry is a column group - move above it.
if (columnGroupModel != null && columnGroupModel.isPartOfAGroup(previousColumnEntryIndex)) {
toPositions.add(firstPositionInGroup - columnGroupModel.getColumnIndexesInGroup(previousColumnEntryIndex).size());
} else {
toPositions.add(firstPositionInGroup - 1);
}
} else {
// If is first member of the unbreakable group, can't move up i.e. out of the group
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, columnGroupModel)){
return;
}
// If previous entry is an unbreakable column group - move above it
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(previousColumnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, previousColumnEntryIndex, columnGroupModel)) {
toPositions.add(firstPositionInGroup - columnGroupModel.getColumnIndexesInGroup(previousColumnEntryIndex).size());
} else {
toPositions.add(firstPositionInGroup - 1);
}
}
}
fireItemsMoved(MoveDirectionEnum.UP, selectedColumnGroupEntries, selectedColumnEntries, postionsGroupedByContiguous, toPositions);
}
}
}
private List<Integer> merge(List<ColumnEntry> selectedColumnEntries, List<ColumnGroupEntry> selectedColumnGroupEntries){
//Convert to positions
List<Integer> columnEntryPositions = ColumnChooserUtils.getColumnEntryPositions(selectedColumnEntries);
List<Integer> columnGroupEntryPositions = ColumnGroupEntry.getColumnGroupEntryPositions(selectedColumnGroupEntries);
//Selected columns + column groups
Set<Integer> allSelectedPositionsSet = new HashSet<Integer>();
allSelectedPositionsSet.addAll(columnEntryPositions);
allSelectedPositionsSet.addAll(columnGroupEntryPositions);
List<Integer> allSelectedPositions = new ArrayList<Integer>(allSelectedPositionsSet);
Collections.sort(allSelectedPositions);
return allSelectedPositions;
}
/**
* Move columns <i>down</i> in the 'Selected' Tree (Right)
*/
@SuppressWarnings("boxing")
protected void moveSelectedDown() {
if (isAnyLeafSelected(selectedTree)) {
if (!isLastLeafSelected(selectedTree)) {
List<ColumnEntry> selectedColumnEntries = getSelectedColumnEntriesIncludingNested(selectedTree);
List<ColumnGroupEntry> selectedColumnGroupEntries = getSelectedColumnGroupEntries(selectedTree);
List<Integer> allSelectedPositions = merge(selectedColumnEntries, selectedColumnGroupEntries);
// Group continuous positions
List<List<Integer>> postionsGroupedByContiguous = PositionUtil.getGroupedByContiguous(allSelectedPositions);
List<Integer> toPositions = new ArrayList<Integer>();
// Set destination positions
for (List<Integer> groupedPositions : postionsGroupedByContiguous) {
// Do these contiguous positions contain a column group ?
boolean columnGroupMoved = columnGroupMoved(groupedPositions, selectedColumnGroupEntries);
// Position of last element in list
int lastListIndex = groupedPositions.size() - 1;
int lastPositionInGroup = groupedPositions.get(lastListIndex);
// Column entry
ColumnEntry columnEntry = getColumnEntryForPosition(selectedTree, lastPositionInGroup);
int columnEntryIndex = columnEntry.getIndex();
// Next Column Entry
ColumnEntry nextColumnEntry = getColumnEntryForPosition(selectedTree, lastPositionInGroup + 1);
// Next column entry will be null the last leaf in the tree is selected
if (nextColumnEntry == null) {
return;
}
int nextColumnEntryIndex = nextColumnEntry.getIndex();
if (columnGroupMoved) {
// If the next entry is a column group - move past it.
if (columnGroupModel != null && columnGroupModel.isPartOfAGroup(nextColumnEntryIndex)) {
toPositions.add(lastPositionInGroup + columnGroupModel.getColumnIndexesInGroup(nextColumnEntryIndex).size());
} else {
toPositions.add(lastPositionInGroup + 1);
}
} else {
// If is last member of the unbreakable group, can't move down i.e. out of the group
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(columnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, nextColumnEntryIndex, columnGroupModel)) {
return;
}
// If next entry is an unbreakable column group - move past it
if (columnGroupModel != null && columnGroupModel.isPartOfAnUnbreakableGroup(nextColumnEntryIndex) && !ColumnGroupUtils.isInTheSameGroup(columnEntryIndex, nextColumnEntryIndex, columnGroupModel)) {
toPositions.add(lastPositionInGroup + columnGroupModel.getColumnIndexesInGroup(nextColumnEntryIndex).size());
} else {
toPositions.add(lastPositionInGroup + 1);
}
}
}
fireItemsMoved(MoveDirectionEnum.DOWN, selectedColumnGroupEntries, selectedColumnEntries, postionsGroupedByContiguous, toPositions);
}
}
}
private boolean columnGroupMoved(List<Integer> fromPositions, List<ColumnGroupEntry> movedColumnGroupEntries) {
for (ColumnGroupEntry columnGroupEntry : movedColumnGroupEntries) {
if(fromPositions.contains(columnGroupEntry.getFirstElementPosition())) return true;
}
return false;
}
/**
* Get the ColumnEntry in the tree with the given position
*/
private ColumnEntry getColumnEntryForPosition(Tree tree, int columnEntryPosition) {
List<ColumnEntry> allColumnEntries = getColumnEntriesIncludingNested(selectedTree.getItems());
for (ColumnEntry columnEntry : allColumnEntries) {
if(columnEntry.getPosition().intValue() == columnEntryPosition){
return columnEntry;
}
}
return null;
}
// Leaf related methods
/**
* Get Leaf index of the selected leaves in the tree
*/
protected List<Integer> getIndexesOfSelectedLeaves(Tree tree) {
List<TreeItem> allSelectedLeaves = ArrayUtil.asList(tree.getSelection());
List<Integer> allSelectedIndexes = new ArrayList<Integer>();
for (TreeItem selectedLeaf : allSelectedLeaves) {
allSelectedIndexes.add(Integer.valueOf(tree.indexOf(selectedLeaf)));
}
return allSelectedIndexes;
}
public void expandAllLeaves() {
List<TreeItem> allLeaves = ArrayUtil.asList(selectedTree.getItems());
for (TreeItem leaf : allLeaves) {
if(isColumnGroupLeaf(leaf)){
ColumnGroupEntry columnGroupEntry = (ColumnGroupEntry) leaf.getData();
leaf.setExpanded(! columnGroupEntry.isCollapsed());
}
}
}
private boolean isColumnGroupLeaf(TreeItem treeItem) {
if(ObjectUtils.isNotNull(treeItem)){
return treeItem.getData() instanceof ColumnGroupEntry;
} else {
return false;
}
}
private boolean isLastLeafSelected(Tree tree) {
TreeItem[] selectedLeaves = tree.getSelection();
for (int i = 0; i < selectedLeaves.length; i++) {
if (tree.indexOf(selectedLeaves[i])+1 == tree.getItemCount()) {
return true;
}
}
return false;
}
private boolean isFirstLeafSelected(Tree tree) {
TreeItem[] selectedLeaves = tree.getSelection();
for (int i = 0; i < selectedLeaves.length; i++) {
if (selectedTree.indexOf(selectedLeaves[i]) == 0) {
return true;
}
}
return false;
}
private boolean isAnyLeafSelected(Tree tree) {
TreeItem[] selectedLeaves = tree.getSelection();
return selectedLeaves != null && selectedLeaves.length > 0;
}
private ColumnEntry getColumnEntryInLeaf(TreeItem leaf) {
if (!isColumnGroupLeaf(leaf)) {
return (ColumnEntry) leaf.getData();
} else {
return null;
}
}
public void removeAllLeaves() {
selectedTree.removeAll();
availableTree.removeAll();
}
// Leaf Selection
public void setSelectionIncludingNested(List<Integer> indexes) {
setSelectionIncludingNested(selectedTree, indexes);
}
/**
* Marks the leaves in the tree as selected
* @param tree containing the leaves
* @param indexes index of the leaf in the tree
*/
protected void setSelection(Tree tree, List<Integer> indexes) {
List<TreeItem> selectedLeaves = new ArrayList<TreeItem>();
for (Integer leafIndex : indexes) {
selectedLeaves.add(tree.getItem(leafIndex.intValue()));
}
tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
tree.showSelection();
}
/**
* Mark the leaves with matching column entries as selected.
* Also checks all the children of the column group leaves
* @param columnEntryIndexes index of the ColumnEntry in the leaf
*/
private void setSelectionIncludingNested(Tree tree, List<Integer> columnEntryIndexes) {
Collection<TreeItem> allLeaves = ArrayUtil.asCollection(tree.getItems());
List<TreeItem> selectedLeaves = new ArrayList<TreeItem>();
for (TreeItem leaf : allLeaves) {
if (!isColumnGroupLeaf(leaf)) {
int index = getColumnEntryInLeaf(leaf).getIndex().intValue();
if (columnEntryIndexes.contains(Integer.valueOf(index))) {
selectedLeaves.add(leaf);
}
} else {
//Check all children in column groups
Collection<TreeItem> columnGroupLeaves = ArrayUtil.asCollection(leaf.getItems());
for (TreeItem columnGroupLeaf : columnGroupLeaves) {
int index = getColumnEntryInLeaf(columnGroupLeaf).getIndex().intValue();
if (columnEntryIndexes.contains(Integer.valueOf(index))) {
selectedLeaves.add(columnGroupLeaf);
}
}
}
}
tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
setGroupsSelectionIfRequired(tree, columnEntryIndexes);
tree.showSelection();
}
/**
* If all the leaves in a group are selected the group is also selected
*/
private void setGroupsSelectionIfRequired(Tree tree, List<Integer> columnEntryIndexes){
Collection<TreeItem> allLeaves = ArrayUtil.asCollection(tree.getItems());
Collection<TreeItem> selectedLeaves = ArrayUtil.asCollection(tree.getSelection());
for (TreeItem leaf : allLeaves) {
if(isColumnGroupLeaf(leaf)){
boolean markSelected = true;
Collection<TreeItem> nestedLeaves = ArrayUtil.asCollection(leaf.getItems());
for (TreeItem nestedLeaf : nestedLeaves) {
ColumnEntry columnEntry = getColumnEntryInLeaf(nestedLeaf);
if(!columnEntryIndexes.contains(columnEntry.getIndex())){
markSelected = false;
}
}
if(markSelected){
selectedLeaves.add(leaf);
}
}
}
tree.setSelection(selectedLeaves.toArray(new TreeItem[] {}));
}
protected Tree getSelectedTree() {
return selectedTree;
}
} | 26,079 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractColumnChooserDialog.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/gui/AbstractColumnChooserDialog.java | package net.sourceforge.nattable.columnChooser.gui;
import net.sourceforge.nattable.util.GUIHelper;
import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
public abstract class AbstractColumnChooserDialog extends Dialog {
protected ListenerList listeners = new ListenerList();;
public AbstractColumnChooserDialog(Shell parent) {
super(parent);
setShellStyle(SWT.CLOSE | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.RESIZE);
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
createButton(parent, IDialogConstants.OK_ID, "Done", true);
}
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
GridDataFactory.fillDefaults().grab(true, true).applyTo(composite);
composite.setLayout(new GridLayout(1, true));
composite.getShell().setText("Column Chooser");
composite.getShell().setImage(GUIHelper.getImage("preferences"));
populateDialogArea(composite);
Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
GridDataFactory.fillDefaults().grab(true, false).applyTo(separator);
return composite;
}
protected abstract void populateDialogArea(Composite composite);
protected void createLabels(Composite parent, String availableStr, String selectedStr) {
boolean availableSet = StringUtils.isNotEmpty(availableStr);
boolean selectedSet = StringUtils.isNotEmpty(selectedStr);
if (availableSet && selectedSet) {
if (availableSet) {
Label availableLabel = new Label(parent, SWT.NONE);
availableLabel.setText(availableStr);
GridDataFactory.swtDefaults().applyTo(availableLabel);
}
Label filler = new Label(parent, SWT.NONE);
GridDataFactory.swtDefaults().span(availableSet ? 1 : 2, 1).applyTo(filler);
if (selectedSet) {
Label selectedLabel = new Label(parent, SWT.NONE);
selectedLabel.setText(selectedStr);
GridDataFactory.swtDefaults().span(2, 1).applyTo(selectedLabel);
}
}
}
public void addListener(Object listener) {
listeners.add(listener);
}
public void removeListener(Object listener) {
listeners.remove(listener);
}
@Override
protected Point getInitialSize() {
return new Point(500, 350);
}
}
| 2,767 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DisplayColumnChooserCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/command/DisplayColumnChooserCommandHandler.java | package net.sourceforge.nattable.columnChooser.command;
import net.sourceforge.nattable.columnChooser.ColumnChooser;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.grid.layer.ColumnHeaderLayer;
import net.sourceforge.nattable.group.ColumnGroupHeaderLayer;
import net.sourceforge.nattable.group.ColumnGroupModel;
import net.sourceforge.nattable.hideshow.ColumnHideShowLayer;
import net.sourceforge.nattable.layer.DataLayer;
import net.sourceforge.nattable.selection.SelectionLayer;
public class DisplayColumnChooserCommandHandler extends AbstractLayerCommandHandler<DisplayColumnChooserCommand> {
private final ColumnHideShowLayer columnHideShowLayer;
private final ColumnGroupHeaderLayer columnGroupHeaderLayer;
private final ColumnGroupModel columnGroupModel;
private final SelectionLayer selectionLayer;
private final DataLayer columnHeaderDataLayer;
private final ColumnHeaderLayer columnHeaderLayer;
public DisplayColumnChooserCommandHandler(
SelectionLayer selectionLayer,
ColumnHideShowLayer columnHideShowLayer,
ColumnHeaderLayer columnHeaderLayer,
DataLayer columnHeaderDataLayer,
ColumnGroupHeaderLayer cgHeader, ColumnGroupModel columnGroupModel) {
this.selectionLayer = selectionLayer;
this.columnHideShowLayer = columnHideShowLayer;
this.columnHeaderLayer = columnHeaderLayer;
this.columnHeaderDataLayer = columnHeaderDataLayer;
this.columnGroupHeaderLayer = cgHeader;
this.columnGroupModel = columnGroupModel;
}
@Override
public boolean doCommand(DisplayColumnChooserCommand command) {
ColumnChooser columnChooser = new ColumnChooser(
command.getNatTable().getShell(),
selectionLayer,
columnHideShowLayer,
columnHeaderLayer,
columnHeaderDataLayer,
columnGroupHeaderLayer,
columnGroupModel);
columnChooser.openDialog();
return true;
}
public Class<DisplayColumnChooserCommand> getCommandClass() {
return DisplayColumnChooserCommand.class;
}
}
| 2,049 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DisplayColumnChooserCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/columnChooser/command/DisplayColumnChooserCommand.java | package net.sourceforge.nattable.columnChooser.command;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
public class DisplayColumnChooserCommand extends AbstractContextFreeCommand {
private final NatTable natTable;
public DisplayColumnChooserCommand(NatTable natTable) {
this.natTable = natTable;
}
public NatTable getNatTable() {
return natTable;
}
}
| 449 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CompositeFreezeLayer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/CompositeFreezeLayer.java | package net.sourceforge.nattable.freeze;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.freeze.command.FreezeCommandHandler;
import net.sourceforge.nattable.freeze.config.DefaultFreezeGridBindings;
import net.sourceforge.nattable.grid.layer.DimensionallyDependentLayer;
import net.sourceforge.nattable.layer.CompositeLayer;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.painter.layer.ILayerPainter;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.util.GUIHelper;
import net.sourceforge.nattable.viewport.ViewportLayer;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
public class CompositeFreezeLayer extends CompositeLayer {
private final FreezeLayer freezeLayer;
private ILayerPainter layerPainter = new FreezableLayerPainter();
public CompositeFreezeLayer(FreezeLayer freezeLayer, ViewportLayer viewportLayer, SelectionLayer selectionLayer) {
this(freezeLayer, viewportLayer, selectionLayer, true);
}
public CompositeFreezeLayer(FreezeLayer freezeLayer, ViewportLayer viewportLayer, SelectionLayer selectionLayer, boolean useDefaultConfiguration) {
super(2, 2);
this.freezeLayer = freezeLayer;
setChildLayer("FROZEN_REGION", freezeLayer, 0, 0);
setChildLayer("FROZEN_ROW_REGION", new DimensionallyDependentLayer(selectionLayer, viewportLayer, freezeLayer), 1, 0);
setChildLayer("FROZEN_COLUMN_REGION", new DimensionallyDependentLayer(selectionLayer, freezeLayer, viewportLayer), 0, 1);
setChildLayer("NONFROZEN_REGION", viewportLayer, 1, 1);
registerCommandHandler(new FreezeCommandHandler(freezeLayer, viewportLayer, selectionLayer));
if (useDefaultConfiguration) {
addConfiguration(new DefaultFreezeGridBindings());
}
}
@Override
public ILayerPainter getLayerPainter() {
return layerPainter;
}
class FreezableLayerPainter extends CompositeLayerPainter {
@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configRegistry) {
super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry);
gc.setClipping(rectangle);
Color oldFg = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_BLUE);
final int freezeWidth = freezeLayer.getWidth() - 1;
if (freezeWidth > 0) {
gc.drawLine(xOffset + freezeWidth, yOffset, xOffset + freezeWidth, yOffset + getHeight() - 1);
}
final int freezeHeight = freezeLayer.getHeight() - 1;
if (freezeHeight > 0) {
gc.drawLine(xOffset, yOffset + freezeHeight, xOffset + getWidth() - 1, yOffset + freezeHeight);
}
gc.setForeground(oldFg);
}
}
}
| 2,822 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeLayer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/FreezeLayer.java | package net.sourceforge.nattable.freeze;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.freeze.event.FreezeEventHandler;
import net.sourceforge.nattable.layer.AbstractLayerTransform;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.IUniqueIndexLayer;
import net.sourceforge.nattable.layer.LayerUtil;
public class FreezeLayer extends AbstractLayerTransform implements IUniqueIndexLayer {
private PositionCoordinate topLeftPosition = new PositionCoordinate(this, -1, -1);
private PositionCoordinate bottomRightPosition = new PositionCoordinate(this, -1, -1);
public FreezeLayer(IUniqueIndexLayer underlyingLayer) {
super(underlyingLayer);
registerEventHandler(new FreezeEventHandler(this));
}
// Coordinates
public PositionCoordinate getTopLeftPosition() {
return topLeftPosition;
}
public void setTopLeftPosition(int leftColumnPosition, int topRowPosition) {
this.topLeftPosition = new PositionCoordinate(this, leftColumnPosition, topRowPosition);
}
public PositionCoordinate getBottomRightPosition() {
return bottomRightPosition;
}
public void setBottomRightPosition(int rightColumnPosition, int bottomRowPosition) {
this.bottomRightPosition = new PositionCoordinate(this, rightColumnPosition, bottomRowPosition);
}
// Column features
@Override
public int getColumnCount() {
if (topLeftPosition.columnPosition >= 0 && bottomRightPosition.columnPosition >= 0) {
return bottomRightPosition.columnPosition - topLeftPosition.columnPosition + 1;
} else {
return 0;
}
}
@Override
public int getPreferredColumnCount() {
return getColumnCount();
}
public int getColumnPositionByIndex(int columnIndex) {
IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
return underlyingToLocalColumnPosition(underlyingLayer, underlyingLayer.getColumnPositionByIndex(columnIndex));
}
@Override
public int localToUnderlyingColumnPosition(int localColumnPosition) {
return topLeftPosition.columnPosition + localColumnPosition;
}
@Override
public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) {
return underlyingColumnPosition - topLeftPosition.columnPosition;
}
@Override
public int getWidth() {
int width = 0;
for (int columnPosition = 0; columnPosition < getColumnCount(); columnPosition++) {
width += getColumnWidthByPosition(columnPosition);
}
return width;
}
@Override
public int getPreferredWidth() {
return getWidth();
}
@Override
public int getStartXOfColumnPosition(int columnPosition) {
IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
final int underlyingColumnPosition = LayerUtil.convertColumnPosition(this, columnPosition, underlyingLayer);
return underlyingLayer.getStartXOfColumnPosition(underlyingColumnPosition) - underlyingLayer.getStartXOfColumnPosition(topLeftPosition.columnPosition);
}
// Row features
@Override
public int getRowCount() {
if (topLeftPosition.rowPosition >= 0 && bottomRightPosition.rowPosition >= 0) {
int frozenRowCount = bottomRightPosition.rowPosition - topLeftPosition.rowPosition + 1;
int underlyingRowCount = getUnderlyingLayer().getRowCount();
return frozenRowCount <= underlyingRowCount ? frozenRowCount : 0;
} else {
return 0;
}
}
@Override
public int getPreferredRowCount() {
return getRowCount();
}
public int getRowPositionByIndex(int rowIndex) {
IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
return underlyingToLocalRowPosition(underlyingLayer, underlyingLayer.getRowPositionByIndex(rowIndex));
}
@Override
public int localToUnderlyingRowPosition(int localRowPosition) {
return topLeftPosition.rowPosition + localRowPosition;
}
@Override
public int underlyingToLocalRowPosition(ILayer sourceUnderlyingLayer, int underlyingRowPosition) {
return underlyingRowPosition - topLeftPosition.rowPosition;
}
@Override
public int getHeight() {
int height = 0;
for (int rowPosition = 0; rowPosition < getRowCount(); rowPosition++) {
height += getRowHeightByPosition(rowPosition);
}
return height;
}
@Override
public int getPreferredHeight() {
return getHeight();
}
@Override
public int getStartYOfRowPosition(int rowPosition) {
IUniqueIndexLayer underlyingLayer = (IUniqueIndexLayer) getUnderlyingLayer();
final int underlyingRowPosition = LayerUtil.convertRowPosition(this, rowPosition, underlyingLayer);
return underlyingLayer.getStartYOfRowPosition(underlyingRowPosition) - underlyingLayer.getStartYOfRowPosition(topLeftPosition.rowPosition);
}
}
| 4,824 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
UnFreezeGridAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/action/UnFreezeGridAction.java | package net.sourceforge.nattable.freeze.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.freeze.command.UnFreezeGridCommand;
import net.sourceforge.nattable.ui.action.IKeyAction;
import org.eclipse.swt.events.KeyEvent;
public class UnFreezeGridAction implements IKeyAction {
public void run(NatTable natTable, KeyEvent event) {
natTable.doCommand(new UnFreezeGridCommand());
}
}
| 434 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeGridAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/action/FreezeGridAction.java | package net.sourceforge.nattable.freeze.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.freeze.command.FreezeSelectionCommand;
import net.sourceforge.nattable.ui.action.IKeyAction;
import org.eclipse.swt.events.KeyEvent;
public class FreezeGridAction implements IKeyAction {
public void run(NatTable natTable, KeyEvent event) {
natTable.doCommand(new FreezeSelectionCommand());
}
}
| 440 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultFreezeGridBindings.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/config/DefaultFreezeGridBindings.java | package net.sourceforge.nattable.freeze.config;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.freeze.action.FreezeGridAction;
import net.sourceforge.nattable.freeze.action.UnFreezeGridAction;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.KeyEventMatcher;
import org.eclipse.swt.SWT;
public class DefaultFreezeGridBindings extends AbstractUiBindingConfiguration {
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CTRL | SWT.SHIFT, 'f'), new FreezeGridAction());
uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CTRL | SWT.SHIFT, 'u'), new UnFreezeGridAction());
}
}
| 803 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeColumnStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/FreezeColumnStrategy.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.freeze.FreezeLayer;
class FreezeColumnStrategy implements IFreezeCoordinatesProvider {
private final FreezeLayer freezeLayer;
private final int columnPosition;
FreezeColumnStrategy(FreezeLayer freezeLayer, int columnPosition) {
this.freezeLayer = freezeLayer;
this.columnPosition = columnPosition;
}
public PositionCoordinate getTopLeftPosition() {
return new PositionCoordinate(freezeLayer, 0, -1);
}
public PositionCoordinate getBottomRightPosition() {
return new PositionCoordinate(freezeLayer, columnPosition, -1);
}
}
| 719 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeSelectionStrategy.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/FreezeSelectionStrategy.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.freeze.FreezeLayer;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.viewport.ViewportLayer;
class FreezeSelectionStrategy implements IFreezeCoordinatesProvider {
private final FreezeLayer freezeLayer;
private final ViewportLayer viewportLayer;
private final SelectionLayer selectionLayer;
FreezeSelectionStrategy(FreezeLayer freezeLayer, ViewportLayer viewportLayer, SelectionLayer selectionLayer) {
this.freezeLayer = freezeLayer;
this.viewportLayer = viewportLayer;
this.selectionLayer = selectionLayer;
}
public PositionCoordinate getTopLeftPosition() {
PositionCoordinate lastSelectedCellPosition = selectionLayer.getLastSelectedCellPosition();
int columnPosition = viewportLayer.getOriginColumnPosition();
if (columnPosition >= lastSelectedCellPosition.columnPosition) {
columnPosition = lastSelectedCellPosition.columnPosition - 1;
}
int rowPosition = viewportLayer.getOriginRowPosition();
if (rowPosition >= lastSelectedCellPosition.rowPosition) {
rowPosition = lastSelectedCellPosition.rowPosition - 1;
}
return new PositionCoordinate(freezeLayer, columnPosition, rowPosition);
}
public PositionCoordinate getBottomRightPosition() {
PositionCoordinate lastSelectedCellPosition = selectionLayer.getLastSelectedCellPosition();
return new PositionCoordinate(freezeLayer, lastSelectedCellPosition.columnPosition - 1, lastSelectedCellPosition.rowPosition - 1);
}
}
| 1,658 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IFreezeCoordinatesProvider.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/IFreezeCoordinatesProvider.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
interface IFreezeCoordinatesProvider {
public PositionCoordinate getTopLeftPosition();
public PositionCoordinate getBottomRightPosition();
}
| 274 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
UnFreezeGridCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/UnFreezeGridCommand.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
public class UnFreezeGridCommand extends AbstractContextFreeCommand implements IFreezeCommand {
}
| 223 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ReorderFrozenAreaCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/ReorderFrozenAreaCommandHandler.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
public class ReorderFrozenAreaCommandHandler extends AbstractLayerCommandHandler<ReorderFrozenAreaCommand> {
public boolean doCommand(ReorderFrozenAreaCommand command) {
return false;
}
public Class<ReorderFrozenAreaCommand> getCommandClass() {
return ReorderFrozenAreaCommand.class;
}
}
| 434 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ReorderFrozenAreaCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/ReorderFrozenAreaCommand.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.layer.ILayer;
public class ReorderFrozenAreaCommand implements ILayerCommand {
public boolean convertToTargetLayer(ILayer targetLayer) {
// TODO Auto-generated method stub
return true;
}
public ReorderFrozenAreaCommand cloneCommand() {
return this;
}
}
| 422 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeColumnCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/FreezeColumnCommand.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.command.AbstractColumnCommand;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.layer.ILayer;
public class FreezeColumnCommand extends AbstractColumnCommand implements IFreezeCommand {
public FreezeColumnCommand(ILayer layer, int columnPosition) {
super(layer, columnPosition);
}
protected FreezeColumnCommand(FreezeColumnCommand command) {
super(command);
}
public ILayerCommand cloneCommand() {
return new FreezeColumnCommand(this);
}
} | 599 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/FreezeCommandHandler.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.freeze.FreezeLayer;
import net.sourceforge.nattable.freeze.event.FreezeEvent;
import net.sourceforge.nattable.freeze.event.UnfreezeEvent;
import net.sourceforge.nattable.selection.SelectionLayer;
import net.sourceforge.nattable.viewport.ViewportLayer;
public class FreezeCommandHandler extends AbstractLayerCommandHandler<IFreezeCommand> {
private final FreezeLayer freezeLayer;
private final ViewportLayer viewportLayer;
private final SelectionLayer selectionLayer;
public FreezeCommandHandler(FreezeLayer freezeLayer, ViewportLayer viewportLayer, SelectionLayer selectionLayer) {
this.freezeLayer = freezeLayer;
this.viewportLayer = viewportLayer;
this.selectionLayer = selectionLayer;
}
public Class<IFreezeCommand> getCommandClass() {
return IFreezeCommand.class;
}
public boolean doCommand(IFreezeCommand command) {
if (command instanceof FreezeColumnCommand) {
FreezeColumnCommand freezeColumnCommand = (FreezeColumnCommand)command;
IFreezeCoordinatesProvider coordinatesProvider = new FreezeColumnStrategy(freezeLayer, freezeColumnCommand.getColumnPosition());
handleFreezeCommand(coordinatesProvider);
return true;
} else if (command instanceof FreezeSelectionCommand) {
IFreezeCoordinatesProvider coordinatesProvider = new FreezeSelectionStrategy(freezeLayer, viewportLayer, selectionLayer);
handleFreezeCommand(coordinatesProvider);
return true;
} else if (command instanceof UnFreezeGridCommand) {
handleUnfreeze();
return true;
}
return false;
}
protected void handleFreezeCommand(IFreezeCoordinatesProvider coordinatesProvider) {
// if not already frozen
if (freezeLayer.getColumnCount() == 0 && freezeLayer.getRowCount() == 0) {
final PositionCoordinate topLeftPosition = coordinatesProvider.getTopLeftPosition();
final PositionCoordinate bottomRightPosition = coordinatesProvider.getBottomRightPosition();
freezeLayer.setTopLeftPosition(topLeftPosition.columnPosition, topLeftPosition.rowPosition);
freezeLayer.setBottomRightPosition(bottomRightPosition.columnPosition, bottomRightPosition.rowPosition);
viewportLayer.setMinimumOriginPosition(bottomRightPosition.columnPosition + 1, bottomRightPosition.rowPosition + 1);
viewportLayer.fireLayerEvent(new FreezeEvent(viewportLayer));
}
}
protected void handleUnfreeze() {
resetFrozenArea();
viewportLayer.fireLayerEvent(new UnfreezeEvent(viewportLayer));
}
private void resetFrozenArea() {
freezeLayer.setTopLeftPosition(-1, -1);
freezeLayer.setBottomRightPosition(-1, -1);
viewportLayer.resetOrigin();
}
} | 2,874 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IFreezeCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/IFreezeCommand.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.command.ILayerCommand;
public interface IFreezeCommand extends ILayerCommand {
}
| 170 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeSelectionCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/command/FreezeSelectionCommand.java | package net.sourceforge.nattable.freeze.command;
import net.sourceforge.nattable.layer.ILayer;
/**
* Will inform the handler to use the selection layer for its freeze coordinates.
*
*/
public class FreezeSelectionCommand implements IFreezeCommand {
public FreezeSelectionCommand() {
}
public boolean convertToTargetLayer(ILayer targetLayer) {
return true;
}
public FreezeSelectionCommand cloneCommand() {
return this;
}
}
| 466 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeEventHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/event/FreezeEventHandler.java | package net.sourceforge.nattable.freeze.event;
import java.util.Collection;
import net.sourceforge.nattable.coordinate.PositionCoordinate;
import net.sourceforge.nattable.coordinate.Range;
import net.sourceforge.nattable.freeze.FreezeLayer;
import net.sourceforge.nattable.layer.event.ILayerEventHandler;
import net.sourceforge.nattable.layer.event.IStructuralChangeEvent;
import net.sourceforge.nattable.layer.event.StructuralDiff;
public class FreezeEventHandler implements ILayerEventHandler<IStructuralChangeEvent> {
private final FreezeLayer freezeLayer;
public FreezeEventHandler(FreezeLayer freezeLayer) {
this.freezeLayer = freezeLayer;
}
public Class<IStructuralChangeEvent> getLayerEventClass() {
return IStructuralChangeEvent.class;
}
public void handleLayerEvent(IStructuralChangeEvent event) {
PositionCoordinate topLeftPosition = freezeLayer.getTopLeftPosition();
PositionCoordinate bottomRightPosition = freezeLayer.getBottomRightPosition();
Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
if (columnDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff columnDiff : columnDiffs) {
switch (columnDiff.getDiffType()) {
case ADD:
Range afterPositionRange = columnDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.columnPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = columnDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.columnPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.columnPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.columnPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.columnPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.columnPosition += leftOffset;
bottomRightPosition.columnPosition += rightOffset;
}
Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
if (rowDiffs != null) {
int leftOffset = 0;
int rightOffset = 0;
for (StructuralDiff rowDiff : rowDiffs) {
switch (rowDiff.getDiffType()) {
case ADD:
Range afterPositionRange = rowDiff.getAfterPositionRange();
if (afterPositionRange.start < topLeftPosition.rowPosition) {
leftOffset += afterPositionRange.size();
}
if (afterPositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset += afterPositionRange.size();
}
break;
case DELETE:
Range beforePositionRange = rowDiff.getBeforePositionRange();
if (beforePositionRange.start < topLeftPosition.rowPosition) {
leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.rowPosition + 1) - beforePositionRange.start;
}
if (beforePositionRange.start <= bottomRightPosition.rowPosition) {
rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.rowPosition + 1) - beforePositionRange.start;
}
break;
}
}
topLeftPosition.rowPosition += leftOffset;
bottomRightPosition.rowPosition += rightOffset;
}
}
}
| 3,459 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
UnfreezeEvent.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/event/UnfreezeEvent.java | package net.sourceforge.nattable.freeze.event;
import java.util.Collection;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.event.StructuralDiff;
import net.sourceforge.nattable.layer.event.StructuralRefreshEvent;
public class UnfreezeEvent extends StructuralRefreshEvent {
public UnfreezeEvent(ILayer layer) {
super(layer);
}
protected UnfreezeEvent(UnfreezeEvent event) {
super(event);
}
public UnfreezeEvent cloneEvent() {
return new UnfreezeEvent(this);
}
public Collection<StructuralDiff> getColumnDiffs() {
return null;
}
public Collection<StructuralDiff> getRowDiffs() {
return null;
}
}
| 695 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
FreezeEvent.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/freeze/event/FreezeEvent.java | package net.sourceforge.nattable.freeze.event;
import java.util.Collection;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.event.StructuralDiff;
import net.sourceforge.nattable.layer.event.StructuralRefreshEvent;
public class FreezeEvent extends StructuralRefreshEvent {
public FreezeEvent(ILayer layer) {
super(layer);
}
protected FreezeEvent(FreezeEvent event) {
super(event);
}
public FreezeEvent cloneEvent() {
return new FreezeEvent(this);
}
public Collection<StructuralDiff> getColumnDiffs() {
return null;
}
public Collection<StructuralDiff> getRowDiffs() {
return null;
}
}
| 684 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColorPersistor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/persistence/ColorPersistor.java | package net.sourceforge.nattable.persistence;
import static net.sourceforge.nattable.persistence.IPersistable.DOT;
import java.util.Properties;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.jface.resource.DataFormatException;
import org.eclipse.jface.resource.StringConverter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
public class ColorPersistor {
public static final String STYLE_PERSISTENCE_PREFIX = "color";
public static final Color DEFAULT_COLOR = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
public static void saveColor(String prefix, Properties properties, Color color) {
prefix = prefix + DOT + STYLE_PERSISTENCE_PREFIX;
if (color == null) {
return;
}
properties.setProperty(prefix, asString(color));
}
public static Color loadColor(String prefix, Properties properties) {
prefix = prefix + DOT + STYLE_PERSISTENCE_PREFIX;
String colorAsString = properties.getProperty(prefix);
if (colorAsString == null) {
return DEFAULT_COLOR;
} else {
return asColor(colorAsString);
}
}
/**
* Create a String representation of the SWT Color
*/
public static String asString(Color color) {
return StringConverter.asString(color.getRGB());
}
/**
* Create a Color instance using the String created by {@link ColorPersistor#asColor(String)}
*/
public static Color asColor(String colorAsString) {
try {
return GUIHelper.getColor(StringConverter.asRGB(colorAsString));
} catch (DataFormatException e) {
return DEFAULT_COLOR;
}
}
}
| 1,648 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IPersistable.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/persistence/IPersistable.java | package net.sourceforge.nattable.persistence;
import java.util.Properties;
/**
* Instances implementing this interface can save and load their
* state from a properties file.
*/
public interface IPersistable {
/**
* Separator used for properties. Example: .BODY.columnWidth.resizableByDefault
*/
public static final String DOT = ".";
/**
* Separator used for values. Example: 0,1,2,3,4
*/
public static final String VALUE_SEPARATOR = ",";
/**
* Save state. The prefix must to be prepended to the property key.
*/
public void saveState(String prefix, Properties properties);
/**
* Restore state. The prefix must to be prepended to the property key.
*
*/
public void loadState(String prefix, Properties properties);
}
| 787 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
StylePersistor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/persistence/StylePersistor.java | package net.sourceforge.nattable.persistence;
import static net.sourceforge.nattable.persistence.IPersistable.DOT;
import static net.sourceforge.nattable.style.CellStyleAttributes.BACKGROUND_COLOR;
import static net.sourceforge.nattable.style.CellStyleAttributes.BORDER_STYLE;
import static net.sourceforge.nattable.style.CellStyleAttributes.FONT;
import static net.sourceforge.nattable.style.CellStyleAttributes.FOREGROUND_COLOR;
import static net.sourceforge.nattable.style.CellStyleAttributes.HORIZONTAL_ALIGNMENT;
import static net.sourceforge.nattable.style.CellStyleAttributes.VERTICAL_ALIGNMENT;
import java.util.Properties;
import net.sourceforge.nattable.style.BorderStyle;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.HorizontalAlignmentEnum;
import net.sourceforge.nattable.style.Style;
import net.sourceforge.nattable.style.VerticalAlignmentEnum;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
/**
* Saves and loads the following components of a style to a properties object.
* - Foreground color
* - Background color
* - Horizontal alignment
* - Vertical alignment
* - Font
* - Border style
*/
public class StylePersistor {
// Style prefix constants
public static final String STYLE_PERSISTENCE_PREFIX = "style";
public static final String BLUE_COLOR_PREFIX = "blue";
public static final String GREEN_COLOR_PREFIX = "green";
public static final String RED_COLOR_PREFIX = "red";
public static final String V_ALIGNMENT_PREFIX = "verticalAlignment";
public static final String H_ALIGNMENT_PREFIX = "horizontalAlignment";
public static final String BG_COLOR_PREFIX = "bg";
public static final String FG_COLOR_PREFIX = "fg";
public static final String FONT_PREFIX = "font";
public static final String BORDER_PREFIX = "border";
// Save
public static void saveStyle(String prefix, Properties properties, Style style) {
prefix = prefix + DOT + STYLE_PERSISTENCE_PREFIX;
saveColor(prefix + DOT + BG_COLOR_PREFIX, properties, style.getAttributeValue(BACKGROUND_COLOR));
saveColor(prefix + DOT + FG_COLOR_PREFIX, properties, style.getAttributeValue(FOREGROUND_COLOR));
saveHAlign(prefix, properties, style.getAttributeValue(HORIZONTAL_ALIGNMENT));
saveVAlign(prefix, properties, style.getAttributeValue(VERTICAL_ALIGNMENT));
saveFont(prefix, properties, style.getAttributeValue(FONT));
saveBorder(prefix, properties, style.getAttributeValue(BORDER_STYLE));
}
protected static void saveVAlign(String prefix, Properties properties, VerticalAlignmentEnum vAlign) {
if (vAlign == null) {
return;
}
properties.setProperty(prefix + DOT + V_ALIGNMENT_PREFIX, vAlign.name());
}
protected static void saveHAlign(String prefix, Properties properties, HorizontalAlignmentEnum hAlign) {
if (hAlign == null) {
return;
}
properties.setProperty(prefix + DOT + H_ALIGNMENT_PREFIX, hAlign.name());
}
protected static void saveBorder(String prefix, Properties properties, BorderStyle borderStyle) {
if (borderStyle == null) {
return;
}
properties.setProperty(prefix + DOT + BORDER_PREFIX, String.valueOf(borderStyle.toString()));
}
protected static void saveFont(String prefix, Properties properties, Font font) {
if (font == null) {
return;
}
properties.setProperty(prefix + DOT + FONT_PREFIX, String.valueOf(font.getFontData()[0].toString()));
}
protected static void saveColor(String prefix, Properties properties, Color color) {
if (color == null) {
return;
}
ColorPersistor.saveColor(prefix, properties, color);
}
// Load
public static Style loadStyle(String prefix, Properties properties) {
Style style = new Style();
prefix = prefix + DOT + STYLE_PERSISTENCE_PREFIX;
// BG Color
String bgColorPrefix = prefix + DOT + BG_COLOR_PREFIX;
Color bgColor = loadColor(bgColorPrefix, properties);
if (bgColor != null) {
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, bgColor);
}
// FG Color
String fgColorPrefix = prefix + DOT + FG_COLOR_PREFIX;
Color fgColor = loadColor(fgColorPrefix, properties);
if (fgColor != null) {
style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, fgColor);
}
// Alignment
String hAlignPrefix = prefix + DOT + H_ALIGNMENT_PREFIX;
HorizontalAlignmentEnum hAlign = loadHAlignment(hAlignPrefix, properties);
if (hAlign != null) {
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, hAlign);
}
String vAlignPrefix = prefix + DOT + V_ALIGNMENT_PREFIX;
VerticalAlignmentEnum vAlign = loadVAlignment(vAlignPrefix, properties);
if (vAlign != null) {
style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, vAlign);
}
// Font
String fontPrefix = prefix + DOT + FONT_PREFIX;
Font font = loadFont(fontPrefix, properties);
if (font != null) {
style.setAttributeValue(CellStyleAttributes.FONT, font);
}
// Border Style
String borderPrefix = prefix + DOT + BORDER_PREFIX;
BorderStyle borderStyle = loadBorderStyle(borderPrefix, properties);
if (borderStyle != null) {
style.setAttributeValue(CellStyleAttributes.BORDER_STYLE, borderStyle);
}
return style;
}
private static BorderStyle loadBorderStyle(String borderPrefix, Properties properties) {
String borderStyle = properties.getProperty(borderPrefix);
if (borderStyle != null) {
return new BorderStyle(borderStyle);
}
return null;
}
private static Font loadFont(String fontPrefix, Properties properties) {
String fontdata = properties.getProperty(fontPrefix);
if (fontdata != null) {
return GUIHelper.getFont(new FontData(fontdata));
}
return null;
}
private static HorizontalAlignmentEnum loadHAlignment(String hAlignPrefix, Properties properties) {
String enumName = properties.getProperty(hAlignPrefix);
if (enumName != null) {
return HorizontalAlignmentEnum.valueOf(enumName);
}
return null;
}
private static VerticalAlignmentEnum loadVAlignment(String vAlignPrefix, Properties properties) {
String enumName = properties.getProperty(vAlignPrefix);
if (enumName != null) {
return VerticalAlignmentEnum.valueOf(enumName);
}
return null;
}
protected static Color loadColor(String prefix, Properties properties) {
return ColorPersistor.loadColor(prefix, properties);
}
}
| 6,591 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ExcelExportProgessBar.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/export/excel/ExcelExportProgessBar.java | package net.sourceforge.nattable.export.excel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
public class ExcelExportProgessBar {
private Shell shell;
private Shell childShell;
private ProgressBar progressBar;
public ExcelExportProgessBar(Shell shell) {
this.shell = shell;
}
public void open(int minValue, int maxValue) {
childShell = new Shell(shell.getDisplay(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
childShell.setText("Exporting to Excel.. please wait");
progressBar = new ProgressBar(childShell, SWT.SMOOTH);
progressBar.setMinimum(minValue);
progressBar.setMaximum(maxValue);
progressBar.setBounds(0, 0, 400, 25);
progressBar.setFocus();
childShell.pack();
childShell.open();
}
public void dispose() {
progressBar.dispose();
childShell.dispose();
}
public void setSelection(int value) {
progressBar.setSelection(value);
}
}
| 984 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ExcelExporter.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/export/excel/ExcelExporter.java | package net.sourceforge.nattable.export.excel;
import static net.sourceforge.nattable.util.ObjectUtils.isNotNull;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.print.command.TurnViewportOnCommand;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.CellStyleProxy;
import net.sourceforge.nattable.util.IClientAreaProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Shell;
public class ExcelExporter {
private static final Object DEFAULT = "";
private static final String EXCEL_HEADER_FILE = "excelExportHeader.txt";
private final ILayer layer;
private final IConfigRegistry configRegistry;
private final IClientAreaProvider originalClientAreaProvider;
public ExcelExporter(ILayer layer, IConfigRegistry configRegistry) {
this.layer = layer;
this.configRegistry = configRegistry;
originalClientAreaProvider = layer.getClientAreaProvider();
}
/**
* Create an HTML table suitable for Excel.
*
* @param outputStream
* to write the output to
* @param positionRectangle
* of the layer to export
* @throws IOException
*/
public void export(final Shell shell, final OutputStream outputStream, final Rectangle positionRectangle) throws IOException {
final ExcelExportProgessBar progressBar = new ExcelExportProgessBar(shell);
Runnable exporter = new Runnable() {
public void run(){
try {
int startRow = positionRectangle.y;
int endRow = startRow + positionRectangle.height;
progressBar.open(startRow, endRow);
writeHeader(outputStream);
outputStream.write(asBytes("<body><table border='1'>"));
for (int rowPosition = startRow; rowPosition <= endRow; rowPosition++) {
progressBar.setSelection(rowPosition);
outputStream.write(asBytes("<tr>\n"));
int startColumn = positionRectangle.x;
int endColumn = startColumn + positionRectangle.width;
for (int colPosition = startColumn; colPosition <= endColumn; colPosition++) {
LayerCell cell = layer.getCellByPosition(colPosition, rowPosition);
outputStream.write(asBytes("\t" + getCellAsHTML(cell) + "\n"));
}
outputStream.write(asBytes("</tr>\n"));
}
outputStream.write(asBytes("</table></body></html>"));
} catch (Exception e) {
logError(e);
} finally {
try {
outputStream.close();
} catch (IOException e) {
logError(e);
}
// These must be fired at the end of the thread execution
layer.setClientAreaProvider(originalClientAreaProvider);
layer.doCommand(new TurnViewportOnCommand());
progressBar.dispose();
}
}
};
// Run with the SWT display so that the progress bar can paint
shell.getDisplay().asyncExec(exporter);
}
private void logError(Exception e) {
System.err.println("Excel Exporter failed: " + e.getMessage());
e.printStackTrace(System.err);
}
private void writeHeader(OutputStream outputStream) throws IOException {
InputStream headerStream = null;
try {
headerStream = this.getClass().getResourceAsStream(EXCEL_HEADER_FILE);
int c;
while ((c = headerStream.read()) != -1) {
outputStream.write(c);
}
} catch (Exception e) {
logError(e);
} finally {
if (isNotNull(headerStream)) {
headerStream.close();
}
}
}
private String getCellAsHTML(LayerCell cell) {
Object dataValue = cell.getDataValue();
return String.format("<td %s>%s</td>",
getStyleAsHtmlAttribute(cell),
dataValue != null ? dataValue : DEFAULT);
}
private String getStyleAsHtmlAttribute(LayerCell cell) {
CellStyleProxy cellStyle = new CellStyleProxy(configRegistry, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
Color fg = cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR);
Color bg = cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR);
Font font = cellStyle.getAttributeValue(CellStyleAttributes.FONT);
return String.format("style='color: %s; background-color: %s; %s;'",
getColorInCSSFormat(fg),
getColorInCSSFormat(bg),
getFontInCSSFormat(font));
}
private String getFontInCSSFormat(Font font) {
FontData fontData = font.getFontData()[0];
String fontName = fontData.getName();
int fontStyle = fontData.getStyle();
String HTML_STYLES[] = new String[] { "NORMAL", "BOLD", "ITALIC" };
return String.format("font: %s; font-family: %s",
fontStyle <= 2 ? HTML_STYLES[fontStyle] : HTML_STYLES[0],
fontName);
}
private String getColorInCSSFormat(Color color) {
return String.format("rgb(%d,%d,%d)",
Integer.valueOf(color.getRed()),
Integer.valueOf(color.getGreen()),
Integer.valueOf(color.getBlue()));
}
private byte[] asBytes(String string) {
return string.getBytes();
}
}
| 5,473 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ExportToExcelAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/export/excel/action/ExportToExcelAction.java | package net.sourceforge.nattable.export.excel.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.export.excel.command.ExportToExcelCommand;
import net.sourceforge.nattable.print.command.TurnViewportOffCommand;
import net.sourceforge.nattable.print.command.TurnViewportOnCommand;
import net.sourceforge.nattable.ui.action.IKeyAction;
import org.eclipse.swt.events.KeyEvent;
public class ExportToExcelAction implements IKeyAction {
public void run(NatTable natTable, KeyEvent event) {
natTable.doCommand(new TurnViewportOffCommand());
natTable.doCommand(new ExportToExcelCommand(natTable.getConfigRegistry(), natTable.getShell()));
natTable.doCommand(new TurnViewportOnCommand());
}
}
| 750 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultExportToExcelBindings.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/export/excel/config/DefaultExportToExcelBindings.java | package net.sourceforge.nattable.export.excel.config;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.export.excel.action.ExportToExcelAction;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.KeyEventMatcher;
import org.eclipse.swt.SWT;
public class DefaultExportToExcelBindings extends AbstractUiBindingConfiguration {
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerKeyBinding(new KeyEventMatcher(SWT.CTRL, 'e'), new ExportToExcelAction());
}
}
| 632 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ExportToExcelCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/export/excel/command/ExportToExcelCommand.java | package net.sourceforge.nattable.export.excel.command;
import net.sourceforge.nattable.command.AbstractContextFreeCommand;
import net.sourceforge.nattable.config.IConfigRegistry;
import org.eclipse.swt.widgets.Shell;
public class ExportToExcelCommand extends AbstractContextFreeCommand {
private IConfigRegistry configRegistry;
private final Shell shell;
public ExportToExcelCommand(IConfigRegistry configRegistry, Shell shell) {
this.configRegistry = configRegistry;
this.shell = shell;
}
public IConfigRegistry getConfigRegistry() {
return configRegistry;
}
public Shell getShell() {
return shell;
}
}
| 652 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ExportToExcelCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/export/excel/command/ExportToExcelCommandHandler.java | package net.sourceforge.nattable.export.excel.command;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.export.excel.ExcelExporter;
import net.sourceforge.nattable.grid.layer.GridLayer;
import net.sourceforge.nattable.print.command.PrintEntireGridCommand;
import net.sourceforge.nattable.util.IClientAreaProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.FileDialog;
public class ExportToExcelCommandHandler extends AbstractLayerCommandHandler<ExportToExcelCommand> {
private final GridLayer gridLayer;
public ExportToExcelCommandHandler(GridLayer gridLayer) {
this.gridLayer = gridLayer;
}
@Override
public boolean doCommand(ExportToExcelCommand command) {
try {
OutputStream outputStream = getOutputStream(command);
if (outputStream == null) {
return true;
}
ExcelExporter excelExporter = new ExcelExporter(gridLayer, command.getConfigRegistry());
// This needs to be done so that the Grid can return all the cells
// not just the ones visible in the viewport
setClientAreaToMaximum();
excelExporter.export(command.getShell(), outputStream, getMaximumLayerSize());
} catch (IOException e) {
throw new RuntimeException("Failed to export table to excel.", e);
}
return true;
}
/**
* Override this to plugin custom OutputStream.
*/
protected OutputStream getOutputStream(ExportToExcelCommand command) throws IOException {
FileDialog dialog = new FileDialog (command.getShell(), SWT.SAVE);
dialog.setFilterPath ("/");
dialog.setOverwrite(true);
dialog.setFileName ("table_export.xls");
dialog.setFilterExtensions(new String [] {"Microsoft Office Excel Workbook(.xls)"});
String fileName = dialog.open();
if(fileName == null){
return null;
}
return new PrintStream(fileName);
}
/**
* @return Position rectangle with the max layer size
*/
private Rectangle getMaximumLayerSize() {
final int width = gridLayer.getWidth();
final int height = gridLayer.getHeight();
int lastRowPosition = gridLayer.getColumnPositionByX(width - 1);
int lastColPosition = gridLayer.getRowPositionByY(height - 1);
return new Rectangle(0, 0, lastRowPosition, lastColPosition);
}
private void setClientAreaToMaximum() {
final Rectangle maxClientArea = new Rectangle(0, 0, gridLayer.getWidth(), gridLayer.getHeight());
gridLayer.setClientAreaProvider(new IClientAreaProvider() {
public Rectangle getClientArea() {
return maxClientArea;
}
});
gridLayer.doCommand(new PrintEntireGridCommand());
}
public Class<ExportToExcelCommand> getCommandClass() {
return ExportToExcelCommand.class;
}
}
| 2,890 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
VisualChangeEventConflater.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/conflation/VisualChangeEventConflater.java | package net.sourceforge.nattable.conflation;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.event.ILayerEvent;
import net.sourceforge.nattable.layer.event.IVisualChangeEvent;
/**
* Gathers all the VisualChangeEvents. When its run, it refreshes/repaints the table.
*
*/
public class VisualChangeEventConflater extends AbstractEventConflater {
private final NatTable natTable;
public VisualChangeEventConflater(NatTable ownerLayer) {
natTable = ownerLayer;
}
@Override
public void addEvent(ILayerEvent event) {
if(event instanceof IVisualChangeEvent){
super.addEvent(event);
}
}
@Override
public Runnable getConflaterTask() {
return new Runnable() {
public void run() {
if (queue.size() > 0) {
natTable.getDisplay().asyncExec(new Runnable() {
public void run() {
natTable.updateResize();
}
});
clearQueue();
}
}
};
}
} | 977 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractEventConflater.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/conflation/AbstractEventConflater.java | package net.sourceforge.nattable.conflation;
import java.util.LinkedList;
import java.util.List;
import net.sourceforge.nattable.layer.event.ILayerEvent;
public abstract class AbstractEventConflater implements IEventConflater {
protected List<ILayerEvent> queue = new LinkedList<ILayerEvent>();
public void addEvent(ILayerEvent event){
queue.add(event);
}
public void clearQueue() {
queue.clear();
}
public int getCount() {
return queue.size();
}
public abstract Runnable getConflaterTask();
}
| 543 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IEventConflater.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/conflation/IEventConflater.java | package net.sourceforge.nattable.conflation;
import net.sourceforge.nattable.layer.event.ILayerEvent;
/**
* A Conflater queues events and periodically runs a task to
* handle those Events. This prevents the table from
* being overwhelmed by ultra fast updates.
*/
public interface IEventConflater {
public abstract void addEvent(ILayerEvent event);
public abstract void clearQueue();
/**
* @return Number of events currently waiting to be handled
*/
public abstract int getCount();
public Runnable getConflaterTask();
} | 563 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
EventConflaterChain.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/conflation/EventConflaterChain.java | package net.sourceforge.nattable.conflation;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.sourceforge.nattable.layer.event.ILayerEvent;
/**
* A Chain of Conflaters. Every conflater in the chain is given the chance to
* queue an event. When the chain runs every conflater in the chain can run its
* own task to handle the events as it sees fit.
*/
public class EventConflaterChain implements IEventConflater {
public static final int DEFAULT_INITIAL_DELAY = 100;
public static final int DEFAULT_REFRESH_INTERVAL = 100;
private final List<IEventConflater> chain = new LinkedList<IEventConflater>();
private boolean started;
private final long refreshInterval;
private final long initialDelay;
private ScheduledExecutorService scheduler;
public EventConflaterChain() {
this(DEFAULT_REFRESH_INTERVAL, DEFAULT_INITIAL_DELAY);
}
public EventConflaterChain(int refreshInterval, int initialDelay) {
this.refreshInterval = refreshInterval;
this.initialDelay = initialDelay;
}
public void add(IEventConflater conflater) {
chain.add(conflater);
}
public void start() {
scheduler = Executors.newScheduledThreadPool(1);
if (!started) {
scheduler.scheduleWithFixedDelay(getConflaterTask(), initialDelay, refreshInterval, TimeUnit.MILLISECONDS);
started = true;
}
}
public void stop() {
if (started) {
scheduler.shutdownNow();
started = false;
}
}
public void addEvent(ILayerEvent event) {
for (IEventConflater eventConflater : chain) {
eventConflater.addEvent(event);
}
}
public void clearQueue() {
for (IEventConflater eventConflater : chain) {
eventConflater.clearQueue();
}
}
public int getCount() {
int count = 0;
for (IEventConflater eventConflater : chain) {
count = count + eventConflater.getCount();
}
return count;
}
public Runnable getConflaterTask() {
return new Runnable() {
public void run() {
for (IEventConflater conflater : chain) {
conflater.getConflaterTask().run();
}
}
};
}
}
| 2,236 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnReorderLayer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/ColumnReorderLayer.java | package net.sourceforge.nattable.reorder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.StringTokenizer;
import net.sourceforge.nattable.coordinate.PositionUtil;
import net.sourceforge.nattable.coordinate.Range;
import net.sourceforge.nattable.layer.AbstractLayerTransform;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.IUniqueIndexLayer;
import net.sourceforge.nattable.layer.LayerUtil;
import net.sourceforge.nattable.layer.event.ColumnStructuralRefreshEvent;
import net.sourceforge.nattable.layer.event.ILayerEvent;
import net.sourceforge.nattable.layer.event.IStructuralChangeEvent;
import net.sourceforge.nattable.layer.event.StructuralDiff;
import net.sourceforge.nattable.reorder.command.ColumnReorderCommandHandler;
import net.sourceforge.nattable.reorder.command.MultiColumnReorderCommandHandler;
import net.sourceforge.nattable.reorder.config.DefaultColumnReorderLayerConfiguration;
import net.sourceforge.nattable.reorder.event.ColumnReorderEvent;
/**
* Adds functionality for reordering column(s)<br/>
* Also responsible for saving/loading the column order state.
*
* @see DefaultColumnReorderLayerConfiguration
*/
public class ColumnReorderLayer extends AbstractLayerTransform implements IUniqueIndexLayer {
public static final String PERSISTENCE_KEY_COLUMN_INDEX_ORDER = ".columnIndexOrder";
private final IUniqueIndexLayer underlyingLayer;
// Position X in the List contains the index of column at position X
private final List<Integer> columnIndexOrder = new ArrayList<Integer>();
private final Map<Integer, Integer> startXCache = new HashMap<Integer, Integer>();
public ColumnReorderLayer(IUniqueIndexLayer underlyingLayer) {
this(underlyingLayer, true);
}
public ColumnReorderLayer(IUniqueIndexLayer underlyingLayer, boolean useDefaultConfiguration) {
super(underlyingLayer);
this.underlyingLayer = underlyingLayer;
populateIndexOrder();
registerCommandHandler(new ColumnReorderCommandHandler(this));
registerCommandHandler(new MultiColumnReorderCommandHandler(this));
if (useDefaultConfiguration) {
addConfiguration(new DefaultColumnReorderLayerConfiguration());
}
}
@Override
public void handleLayerEvent(ILayerEvent event) {
if (event instanceof IStructuralChangeEvent) {
IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
if (structuralChangeEvent.isHorizontalStructureChanged()) {
Collection<StructuralDiff> structuralDiffs = structuralChangeEvent.getColumnDiffs();
if (structuralDiffs == null) {
// Assume everything changed
columnIndexOrder.clear();
populateIndexOrder();
} else {
for (StructuralDiff structuralDiff : structuralDiffs) {
switch (structuralDiff.getDiffType()) {
case ADD:
columnIndexOrder.clear();
populateIndexOrder();
break;
case DELETE:
columnIndexOrder.clear();
populateIndexOrder();
break;
}
}
}
invalidateCache();
}
}
super.handleLayerEvent(event);
}
// Persistence
@Override
public void saveState(String prefix, Properties properties) {
super.saveState(prefix, properties);
if (columnIndexOrder.size() > 0) {
StringBuilder strBuilder = new StringBuilder();
for (Integer index : columnIndexOrder) {
strBuilder.append(index);
strBuilder.append(',');
}
properties.setProperty(prefix + PERSISTENCE_KEY_COLUMN_INDEX_ORDER, strBuilder.toString());
}
}
@Override
public void loadState(String prefix, Properties properties) {
super.loadState(prefix, properties);
String property = properties.getProperty(prefix + PERSISTENCE_KEY_COLUMN_INDEX_ORDER);
if (property != null) {
List<Integer> newColumnIndexOrder = new ArrayList<Integer>();
StringTokenizer tok = new StringTokenizer(property, ",");
while (tok.hasMoreTokens()) {
String index = tok.nextToken();
newColumnIndexOrder.add(Integer.valueOf(index));
}
if(isRestoredStateValid(newColumnIndexOrder)){
columnIndexOrder.clear();
columnIndexOrder.addAll(newColumnIndexOrder);
}
}
fireLayerEvent(new ColumnStructuralRefreshEvent(this));
}
/**
* Ensure that columns haven't changed in the underlying data source
* @param newColumnIndexOrder restored from the properties file.
*/
protected boolean isRestoredStateValid(List<Integer> newColumnIndexOrder) {
if (newColumnIndexOrder.size() != getColumnCount()){
System.err.println(
"Number of persisted columns (" + newColumnIndexOrder.size() + ") " +
"is not the same as the number of columns in the data source (" + getColumnCount() + ").\n" +
"Skipping restore of column ordering");
return false;
}
for (Integer index : newColumnIndexOrder) {
if(!columnIndexOrder.contains(index)){
System.err.println(
"Column index: " + index + " being restored, is not a available in the data soure.\n" +
"Skipping restore of column ordering");
return false;
}
}
return true;
}
// Columns
@Override
public int getColumnIndexByPosition(int columnPosition) {
if (columnPosition >= 0 && columnPosition < columnIndexOrder.size()) {
return columnIndexOrder.get(columnPosition).intValue();
} else {
return -1;
}
}
public int getColumnPositionByIndex(int columnIndex) {
return columnIndexOrder.indexOf(Integer.valueOf(columnIndex));
}
@Override
public int localToUnderlyingColumnPosition(int localColumnPosition) {
int columnIndex = getColumnIndexByPosition(localColumnPosition);
return underlyingLayer.getColumnPositionByIndex(columnIndex);
}
@Override
public int underlyingToLocalColumnPosition(ILayer sourceUnderlyingLayer, int underlyingColumnPosition) {
int columnIndex = underlyingLayer.getColumnIndexByPosition(underlyingColumnPosition);
return getColumnPositionByIndex(columnIndex);
}
@Override
public Collection<Range> underlyingToLocalColumnPositions(ILayer sourceUnderlyingLayer, Collection<Range> underlyingColumnPositionRanges) {
List<Integer> reorderedColumnPositions = new ArrayList<Integer>();
for (Range underlyingColumnPositionRange : underlyingColumnPositionRanges) {
for (int underlyingColumnPosition = underlyingColumnPositionRange.start; underlyingColumnPosition < underlyingColumnPositionRange.end; underlyingColumnPosition++) {
int localColumnPosition = underlyingToLocalColumnPosition(sourceUnderlyingLayer, underlyingColumnPositionRange.start);
reorderedColumnPositions.add(Integer.valueOf(localColumnPosition));
}
}
Collections.sort(reorderedColumnPositions);
return PositionUtil.getRanges(reorderedColumnPositions);
}
// X
@Override
public int getColumnPositionByX(int x) {
return LayerUtil.getColumnPositionByX(this, x);
}
@Override
public int getStartXOfColumnPosition(int targetColumnPosition) {
Integer cachedStartX = startXCache.get(Integer.valueOf(targetColumnPosition));
if (cachedStartX != null) {
return cachedStartX.intValue();
}
int aggregateWidth = 0;
for (int columnPosition = 0; columnPosition < targetColumnPosition; columnPosition++) {
aggregateWidth += underlyingLayer.getColumnWidthByPosition(localToUnderlyingColumnPosition(columnPosition));
}
startXCache.put(Integer.valueOf(targetColumnPosition), Integer.valueOf(aggregateWidth));
return aggregateWidth;
}
private void populateIndexOrder() {
ILayer underlyingLayer = getUnderlyingLayer();
for (int columnPosition = 0; columnPosition < underlyingLayer.getColumnCount(); columnPosition++) {
columnIndexOrder.add(Integer.valueOf(underlyingLayer.getColumnIndexByPosition(columnPosition)));
}
}
// Vertical features
// Rows
public int getRowPositionByIndex(int rowIndex) {
return underlyingLayer.getRowPositionByIndex(rowIndex);
}
/**
* Moves the column to the <i>LEFT</i> of the toColumnPosition
* @param fromColumnPosition column position to move
* @param toColumnPosition position to move the column to
*/
private void moveColumn(int fromColumnPosition, int toColumnPosition) {
Integer fromColumnIndex = columnIndexOrder.get(fromColumnPosition);
columnIndexOrder.add(toColumnPosition, fromColumnIndex);
columnIndexOrder.remove(fromColumnPosition + (fromColumnPosition > toColumnPosition ? 1 : 0));
invalidateCache();
}
public void reorderColumnPosition(int fromColumnPosition, int toColumnPosition) {
moveColumn(fromColumnPosition, toColumnPosition);
fireLayerEvent(new ColumnReorderEvent(this, fromColumnPosition, toColumnPosition));
}
public void reorderMultipleColumnPositions(List<Integer> fromColumnPositions, int toColumnPosition) {
// Moving from left to right
final int fromColumnPositionsCount = fromColumnPositions.size();
if (toColumnPosition > fromColumnPositions.get(fromColumnPositionsCount - 1).intValue()) {
int firstColumnPosition = fromColumnPositions.get(0).intValue();
for (int columnCount = 0; columnCount < fromColumnPositionsCount; columnCount++) {
final int fromColumnPosition = fromColumnPositions.get(0).intValue();
moveColumn(fromColumnPosition, toColumnPosition);
if (fromColumnPosition < firstColumnPosition) {
firstColumnPosition = fromColumnPosition;
}
}
} else if (toColumnPosition < fromColumnPositions.get(fromColumnPositionsCount - 1).intValue()) {
// Moving from right to left
int targetColumnPosition = toColumnPosition;
for (Integer fromColumnPosition : fromColumnPositions) {
final int fromColumnPositionInt = fromColumnPosition.intValue();
moveColumn(fromColumnPositionInt, targetColumnPosition++);
}
}
fireLayerEvent(new ColumnReorderEvent(this, fromColumnPositions, toColumnPosition));
}
private void invalidateCache() {
startXCache.clear();
}
} | 10,156 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnReorderDragMode.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/action/ColumnReorderDragMode.java | package net.sourceforge.nattable.reorder.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.layer.cell.LayerCell;
import net.sourceforge.nattable.painter.IOverlayPainter;
import net.sourceforge.nattable.reorder.command.ColumnReorderCommand;
import net.sourceforge.nattable.ui.action.IDragMode;
import net.sourceforge.nattable.ui.util.CellEdgeDetectUtil;
import net.sourceforge.nattable.ui.util.CellEdgeEnum;
import net.sourceforge.nattable.util.GUIHelper;
import net.sourceforge.nattable.viewport.command.ViewportSelectColumnCommand;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
/**
* Default {@link IDragMode} invoked for 'left click + drag' on the column header.<br/>
* It does the following when invoked: <br/>
* <ol>
* <li>Fires a column reorder command, to move columns</li>
* <li>Overlays a black line indicating the new column position</li>
* </ol>
*/
public class ColumnReorderDragMode implements IDragMode {
protected int dragFromGridColumnPosition = -1;
protected int dragToGridColumnPosition = -1;
protected int dragToColumnHandleX = -1;
protected ColumnReorderOverlayPainter overlayPainter = new ColumnReorderOverlayPainter();
protected LabelStack regionLabels;
protected boolean isValidCoordinate = false;
private CellEdgeEnum moveDirection = null;
public void mouseDown(NatTable natTable, MouseEvent event) {
natTable.forceFocus();
regionLabels = natTable.getRegionLabelsByXY(event.x, event.y);
dragFromGridColumnPosition = natTable.getColumnPositionByX(event.x);
dragToGridColumnPosition = -1;
dragToColumnHandleX = -1;
selectDragFocusColumn(natTable, event, dragFromGridColumnPosition);
natTable.addOverlayPainter(overlayPainter);
}
public void mouseMove(NatTable natTable, MouseEvent event) {
if (event.x > natTable.getWidth()) {
return;
}
Point dragPt = new Point(event.x, event.y);
int gridColumnPosition = natTable.getColumnPositionByX(event.x);
if (gridColumnPosition >= 0) {
int gridRowPosition = natTable.getRowPositionByY(event.y);
LayerCell cell = natTable.getCellByPosition(gridColumnPosition, gridRowPosition);
if (cell == null) {
return;
}
Rectangle selectedColumnHeaderRect = cell.getBounds();
int tmpDragToGridColumnPosition = 0;
moveDirection = CellEdgeDetectUtil.getHorizontalCellEdge(selectedColumnHeaderRect, dragPt);
switch (moveDirection) {
case LEFT:
tmpDragToGridColumnPosition = gridColumnPosition;
if ((isValidCoordinate = isValidTargetColumnPosition(natTable, dragFromGridColumnPosition,tmpDragToGridColumnPosition, event))) {
dragToGridColumnPosition = tmpDragToGridColumnPosition;
dragToColumnHandleX = selectedColumnHeaderRect.x;
}else {
dragToColumnHandleX = 0;
}
break;
case RIGHT:
tmpDragToGridColumnPosition = gridColumnPosition + 1;
if ((isValidCoordinate = isValidTargetColumnPosition(natTable, dragFromGridColumnPosition, tmpDragToGridColumnPosition, event))) {
dragToGridColumnPosition = tmpDragToGridColumnPosition;
dragToColumnHandleX = selectedColumnHeaderRect.x + selectedColumnHeaderRect.width;
} else {
dragToColumnHandleX = 0;
}
break;
}
natTable.redraw(0, 0, natTable.getWidth(), natTable.getHeight(), false);
}
}
protected boolean isValidTargetColumnPosition(ILayer natLayer, int dragFromColumnPosition, int dragToGridColumnPosition, MouseEvent event) {
return true;
}
public void mouseUp(NatTable natTable, MouseEvent event) {
natTable.removeOverlayPainter(overlayPainter);
if (dragFromGridColumnPosition >= 0 && dragToGridColumnPosition >= 0 && isValidCoordinate) {
fireMoveCommand(natTable);
if(CellEdgeEnum.RIGHT == moveDirection) {
selectDragFocusColumn(natTable, event, dragToGridColumnPosition - 1);
} else {
selectDragFocusColumn(natTable, event, dragToGridColumnPosition);
}
}
}
protected void fireMoveCommand(NatTable natTable) {
natTable.doCommand(new ColumnReorderCommand(natTable, dragFromGridColumnPosition, dragToGridColumnPosition));
}
protected void selectDragFocusColumn(ILayer natLayer, MouseEvent event, int focusedColumnPosition) {
boolean shiftMask = (SWT.SHIFT & event.stateMask) != 0;
boolean controlMask = (SWT.CONTROL & event.stateMask) != 0;
natLayer.doCommand(new ViewportSelectColumnCommand(natLayer, focusedColumnPosition, shiftMask, controlMask));
}
private class ColumnReorderOverlayPainter implements IOverlayPainter {
public void paintOverlay(GC gc, ILayer layer) {
if (dragFromGridColumnPosition >= 0) {
Color orgBgColor = gc.getBackground();
gc.setBackground(GUIHelper.COLOR_DARK_GRAY);
gc.fillRectangle(dragToColumnHandleX - 1, 0, 2, layer.getHeight());
gc.setBackground(orgBgColor);
}
}
}
}
| 5,203 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultReorderBindings.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/config/DefaultReorderBindings.java | package net.sourceforge.nattable.reorder.config;
import net.sourceforge.nattable.config.AbstractUiBindingConfiguration;
import net.sourceforge.nattable.reorder.action.ColumnReorderDragMode;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.MouseEventMatcher;
import org.eclipse.swt.SWT;
/**
* Column reorder bindings. Added by {@link DefaultColumnReorderLayerConfiguration}
*/
public class DefaultReorderBindings extends AbstractUiBindingConfiguration {
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerMouseDragMode(MouseEventMatcher.columnHeaderLeftClick(SWT.NONE), new ColumnReorderDragMode());
}
}
| 735 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultColumnReorderLayerConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/config/DefaultColumnReorderLayerConfiguration.java | package net.sourceforge.nattable.reorder.config;
import net.sourceforge.nattable.config.AggregateConfiguration;
import net.sourceforge.nattable.reorder.ColumnReorderLayer;
/**
* Added by the {@link ColumnReorderLayer}
*/
public class DefaultColumnReorderLayerConfiguration extends AggregateConfiguration {
public DefaultColumnReorderLayerConfiguration() {
addColumnReorderUIBindings();
}
protected void addColumnReorderUIBindings() {
addConfiguration(new DefaultReorderBindings());
}
}
| 501 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnReorderCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/command/ColumnReorderCommandHandler.java | package net.sourceforge.nattable.reorder.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.reorder.ColumnReorderLayer;
public class ColumnReorderCommandHandler extends AbstractLayerCommandHandler<ColumnReorderCommand> {
private final ColumnReorderLayer columnReorderLayer;
public ColumnReorderCommandHandler(ColumnReorderLayer columnReorderLayer) {
this.columnReorderLayer = columnReorderLayer;
}
public Class<ColumnReorderCommand> getCommandClass() {
return ColumnReorderCommand.class;
}
@Override
protected boolean doCommand(ColumnReorderCommand command) {
int fromColumnPosition = command.getFromColumnPosition();
int toColumnPosition = command.getToColumnPosition();
columnReorderLayer.reorderColumnPosition(fromColumnPosition, toColumnPosition);
return true;
}
}
| 862 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiColumnReorderCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/command/MultiColumnReorderCommandHandler.java | package net.sourceforge.nattable.reorder.command;
import java.util.List;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.reorder.ColumnReorderLayer;
public class MultiColumnReorderCommandHandler extends AbstractLayerCommandHandler<MultiColumnReorderCommand> {
private final ColumnReorderLayer columnReorderLayer;
public MultiColumnReorderCommandHandler(ColumnReorderLayer columnReorderLayer) {
this.columnReorderLayer = columnReorderLayer;
}
public Class<MultiColumnReorderCommand> getCommandClass() {
return MultiColumnReorderCommand.class;
}
@Override
protected boolean doCommand(MultiColumnReorderCommand command) {
List<Integer> fromColumnPositions = command.getFromColumnPositions();
int toColumnPosition = command.getToColumnPosition();
columnReorderLayer.reorderMultipleColumnPositions(fromColumnPositions, toColumnPosition);
return true;
}
}
| 938 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnReorderCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/command/ColumnReorderCommand.java | package net.sourceforge.nattable.reorder.command;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.command.LayerCommandUtil;
import net.sourceforge.nattable.coordinate.ColumnPositionCoordinate;
import net.sourceforge.nattable.layer.ILayer;
public class ColumnReorderCommand implements ILayerCommand {
private ColumnPositionCoordinate fromColumnPositionCoordinate;
private ColumnPositionCoordinate toColumnPositionCoordinate;
public ColumnReorderCommand(ILayer layer, int fromColumnPosition, int toColumnPosition) {
fromColumnPositionCoordinate = new ColumnPositionCoordinate(layer, fromColumnPosition);
toColumnPositionCoordinate = new ColumnPositionCoordinate(layer, toColumnPosition);
}
protected ColumnReorderCommand(ColumnReorderCommand command) {
this.fromColumnPositionCoordinate = command.fromColumnPositionCoordinate;
this.toColumnPositionCoordinate = command.toColumnPositionCoordinate;
}
public int getFromColumnPosition() {
return fromColumnPositionCoordinate.getColumnPosition();
}
public int getToColumnPosition() {
return toColumnPositionCoordinate.getColumnPosition();
}
public boolean convertToTargetLayer(ILayer targetLayer) {
fromColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(fromColumnPositionCoordinate, targetLayer);
toColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(toColumnPositionCoordinate, targetLayer);
return fromColumnPositionCoordinate != null && toColumnPositionCoordinate != null;
}
public ColumnReorderCommand cloneCommand() {
return new ColumnReorderCommand(this);
}
}
| 1,702 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
MultiColumnReorderCommand.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/command/MultiColumnReorderCommand.java | package net.sourceforge.nattable.reorder.command;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.nattable.command.ILayerCommand;
import net.sourceforge.nattable.command.LayerCommandUtil;
import net.sourceforge.nattable.coordinate.ColumnPositionCoordinate;
import net.sourceforge.nattable.layer.ILayer;
public class MultiColumnReorderCommand implements ILayerCommand {
private List<ColumnPositionCoordinate> fromColumnPositionCoordinates;
private ColumnPositionCoordinate toColumnPositionCoordinate;
public MultiColumnReorderCommand(ILayer layer, List<Integer> fromColumnPositions, int toColumnPositions) {
fromColumnPositionCoordinates = new ArrayList<ColumnPositionCoordinate>();
for (Integer fromColumnPosition : fromColumnPositions) {
fromColumnPositionCoordinates.add(new ColumnPositionCoordinate(layer, fromColumnPosition.intValue()));
}
toColumnPositionCoordinate = new ColumnPositionCoordinate(layer, toColumnPositions);
}
protected MultiColumnReorderCommand(MultiColumnReorderCommand command) {
this.fromColumnPositionCoordinates = new ArrayList<ColumnPositionCoordinate>(command.fromColumnPositionCoordinates);
this.toColumnPositionCoordinate = command.toColumnPositionCoordinate;
}
public List<Integer> getFromColumnPositions() {
List<Integer> fromColumnPositions = new ArrayList<Integer>();
for (ColumnPositionCoordinate fromColumnPositionCoordinate : fromColumnPositionCoordinates) {
fromColumnPositions.add(Integer.valueOf(fromColumnPositionCoordinate.getColumnPosition()));
}
return fromColumnPositions;
}
public int getToColumnPosition() {
return toColumnPositionCoordinate.getColumnPosition();
}
public boolean convertToTargetLayer(ILayer targetLayer) {
List<ColumnPositionCoordinate> convertedFromColumnPositionCoordinates = new ArrayList<ColumnPositionCoordinate>();
for (ColumnPositionCoordinate fromColumnPositionCoordinate : fromColumnPositionCoordinates) {
ColumnPositionCoordinate convertedFromColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(fromColumnPositionCoordinate, targetLayer);
if (convertedFromColumnPositionCoordinate != null) {
convertedFromColumnPositionCoordinates.add(convertedFromColumnPositionCoordinate);
}
}
fromColumnPositionCoordinates = convertedFromColumnPositionCoordinates;
toColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(toColumnPositionCoordinate, targetLayer);
return fromColumnPositionCoordinates.size() > 0 && toColumnPositionCoordinate != null;
}
public MultiColumnReorderCommand cloneCommand() {
return new MultiColumnReorderCommand(this);
}
}
| 2,751 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ColumnReorderEvent.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/reorder/event/ColumnReorderEvent.java | package net.sourceforge.nattable.reorder.event;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import net.sourceforge.nattable.coordinate.PositionUtil;
import net.sourceforge.nattable.coordinate.Range;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.event.ColumnStructuralChangeEvent;
import net.sourceforge.nattable.layer.event.StructuralDiff;
import net.sourceforge.nattable.layer.event.StructuralDiff.DiffTypeEnum;
public class ColumnReorderEvent extends ColumnStructuralChangeEvent {
private Collection<Range> beforeFromColumnPositionRanges;
private int beforeToColumnPosition;
public ColumnReorderEvent(ILayer layer, int beforeFromColumnPosition, int beforeToColumnPosition) {
this(layer, Arrays.asList(new Integer[] { Integer.valueOf(beforeFromColumnPosition) }), beforeToColumnPosition);
}
public ColumnReorderEvent(ILayer layer, List<Integer> beforeFromColumnPositions, int beforeToColumnPosition) {
super(layer);
this.beforeFromColumnPositionRanges = PositionUtil.getRanges(beforeFromColumnPositions);
this.beforeToColumnPosition = beforeToColumnPosition;
List<Integer> allColumnPositions = new ArrayList<Integer>(beforeFromColumnPositions);
allColumnPositions.add(beforeToColumnPosition);
setColumnPositionRanges(PositionUtil.getRanges(allColumnPositions));
}
public ColumnReorderEvent(ColumnReorderEvent event) {
super(event);
this.beforeFromColumnPositionRanges = event.beforeFromColumnPositionRanges;
this.beforeToColumnPosition = event.beforeToColumnPosition;
}
public Collection<Range> getBeforeFromColumnPositionRanges() {
return beforeFromColumnPositionRanges;
}
public int getBeforeToColumnPosition() {
return beforeToColumnPosition;
}
public Collection<StructuralDiff> getColumnDiffs() {
Collection<StructuralDiff> columnDiffs = new ArrayList<StructuralDiff>();
Collection<Range> beforeFromColumnPositionRanges = getBeforeFromColumnPositionRanges();
int afterAddColumnPosition = beforeToColumnPosition;
for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
if (beforeFromColumnPositionRange.start < beforeToColumnPosition) {
afterAddColumnPosition -= Math.min(beforeFromColumnPositionRange.end, beforeToColumnPosition) - beforeFromColumnPositionRange.start;
} else {
break;
}
}
int cumulativeAddSize = 0;
for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
cumulativeAddSize += beforeFromColumnPositionRange.size();
}
int offset = 0;
for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
int afterDeleteColumnPosition = beforeFromColumnPositionRange.start - offset;
if (afterAddColumnPosition < afterDeleteColumnPosition) {
afterDeleteColumnPosition += cumulativeAddSize;
}
columnDiffs.add(new StructuralDiff(DiffTypeEnum.DELETE, beforeFromColumnPositionRange, new Range(afterDeleteColumnPosition, afterDeleteColumnPosition)));
offset += beforeFromColumnPositionRange.size();
}
Range beforeAddRange = new Range(beforeToColumnPosition, beforeToColumnPosition);
offset = 0;
for (Range beforeFromColumnPositionRange : beforeFromColumnPositionRanges) {
int size = beforeFromColumnPositionRange.size();
columnDiffs.add(new StructuralDiff(DiffTypeEnum.ADD, beforeAddRange, new Range(afterAddColumnPosition + offset, afterAddColumnPosition + offset + size)));
offset += size;
}
return columnDiffs;
}
@Override
public boolean convertToLocal(ILayer targetLayer) {
beforeFromColumnPositionRanges = targetLayer.underlyingToLocalColumnPositions(getLayer(), beforeFromColumnPositionRanges);
beforeToColumnPosition = targetLayer.underlyingToLocalColumnPosition(getLayer(), beforeToColumnPosition);
if (beforeToColumnPosition >= 0) {
return super.convertToLocal(targetLayer);
} else {
return false;
}
}
public ColumnReorderEvent cloneEvent() {
return new ColumnReorderEvent(this);
}
}
| 4,118 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AggregateConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/AggregateConfiguration.java | package net.sourceforge.nattable.config;
import java.util.Collection;
import java.util.LinkedList;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
/**
* Aggregates {@link IConfiguration} objects and invokes configure methods on all its members.
*/
public class AggregateConfiguration implements IConfiguration {
private final Collection<IConfiguration> configurations = new LinkedList<IConfiguration>();
public void addConfiguration(IConfiguration configuration) {
configurations.add(configuration);
}
public void configureLayer(ILayer layer) {
for (IConfiguration configuration : configurations) {
configuration.configureLayer(layer);
}
}
public void configureRegistry(IConfigRegistry configRegistry) {
for (IConfiguration configuration : configurations) {
configuration.configureRegistry(configRegistry);
}
}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
for (IConfiguration configuration : configurations) {
configuration.configureUiBindings(uiBindingRegistry);
}
}
}
| 1,137 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
NullComparator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/NullComparator.java | package net.sourceforge.nattable.config;
import java.io.Serializable;
import java.util.Comparator;
/**
* GlazedLists require that the comparator be set to 'null' if a column is not sortable.<br/>
* If a null value is set in the {@link IConfigRegistry} it will attempt to find<br/>
* other matching values.<br/>
* This comparator can be set in the {@link ConfigRegistry} to indicate that the column can not be sorted.
*
* @see SortableGridExample
*/
public class NullComparator implements Comparator<Object>, Serializable {
private static final long serialVersionUID = -6945858872109267371L;
public int compare(Object o1, Object o2) {
return 0;
}
}
| 687 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractUiBindingConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/AbstractUiBindingConfiguration.java | package net.sourceforge.nattable.config;
import net.sourceforge.nattable.layer.ILayer;
public abstract class AbstractUiBindingConfiguration implements IConfiguration {
public void configureLayer(ILayer layer) {}
public void configureRegistry(IConfigRegistry configRegistry) {}
}
| 299 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/IConfiguration.java | package net.sourceforge.nattable.config;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.data.validate.IDataValidator;
import net.sourceforge.nattable.layer.AbstractLayer;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
/**
* Configurations can be added to NatTable/ILayer to modify default behavior.
* These will be processed when {@link NatTable#configure()} is invoked.
*
* Default configurations are added to most layers {@link AbstractLayer#addConfiguration()}.
* You can turn off default configuration for an {@link ILayer} by setting auto configure to false
* in the constructor.
*/
public interface IConfiguration {
public void configureLayer(ILayer layer);
/**
* Configure NatTable's {@link IConfigRegistry} upon receiving this call back.
* A mechanism to plug-in custom {@link ICellPainter}, {@link IDataValidator} etc.
*/
public void configureRegistry(IConfigRegistry configRegistry);
/**
* Configure NatTable's {@link IConfigRegistry} upon receiving this call back
* A mechanism to customize key/mouse bindings.
*/
public void configureUiBindings(UiBindingRegistry uiBindingRegistry);
}
| 1,274 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ConfigRegistry.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/ConfigRegistry.java | package net.sourceforge.nattable.config;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.nattable.style.ConfigAttribute;
import net.sourceforge.nattable.style.DefaultDisplayModeOrdering;
import net.sourceforge.nattable.style.DisplayMode;
import net.sourceforge.nattable.style.IDisplayModeOrdering;
public class ConfigRegistry implements IConfigRegistry {
// Map<configAttributeType, Map<displayMode, Map<configLabel, value>>>
Map<ConfigAttribute<?>, Map<String, Map<String, ?>>> configRegistry = new HashMap<ConfigAttribute<?>, Map<String, Map<String, ?>>>();
public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode, String...configLabels) {
return getConfigAttribute(configAttribute, targetDisplayMode, Arrays.asList(configLabels));
}
@SuppressWarnings("unchecked")
public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode, List<String> configLabels) {
T attributeValue = null;
Map<String, Map<String, ?>> displayModeConfigAttributeMap = configRegistry.get(configAttribute);
if (displayModeConfigAttributeMap != null) {
for (String displayMode : displayModeOrdering.getDisplayModeOrdering(targetDisplayMode)) {
Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);
if (configAttributeMap != null) {
for (String configLabel : configLabels) {
attributeValue = configAttributeMap.get(configLabel);
if (attributeValue != null) {
return attributeValue;
}
}
// default config type
attributeValue = configAttributeMap.get(null);
if (attributeValue != null) {
return attributeValue;
}
}
}
}
return attributeValue;
}
@SuppressWarnings("unchecked")
public <T> T getSpecificConfigAttribute(ConfigAttribute<T> configAttribute, String displayMode, String configLabel) {
T attributeValue = null;
Map<String, Map<String, ?>> displayModeConfigAttributeMap = configRegistry.get(configAttribute);
if (displayModeConfigAttributeMap != null) {
Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);
if (configAttributeMap != null) {
attributeValue = configAttributeMap.get(configLabel);
if (attributeValue != null) {
return attributeValue;
}
}
}
return attributeValue;
}
public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue) {
registerConfigAttribute(configAttribute, attributeValue, DisplayMode.NORMAL);
}
public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue, String displayMode) {
registerConfigAttribute(configAttribute, attributeValue, displayMode, null);
}
@SuppressWarnings("unchecked")
public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue, String displayMode, String configLabel) {
Map<String, Map<String, ?>> displayModeConfigAttributeMap = configRegistry.get(configAttribute);
if (displayModeConfigAttributeMap == null) {
displayModeConfigAttributeMap = new HashMap<String, Map<String, ?>>();
configRegistry.put(configAttribute, displayModeConfigAttributeMap);
}
Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);
if (configAttributeMap == null) {
configAttributeMap = new HashMap<String, T>();
displayModeConfigAttributeMap.put(displayMode, configAttributeMap);
}
configAttributeMap.put(configLabel, attributeValue);
};
@SuppressWarnings("unchecked")
public <T> void unregisterConfigAttribute(Class<T> configAttributeType, String displayMode, String configLabel) {
Map<String, Map<String, ?>> displayModeConfigAttributeMap = configRegistry.get(configAttributeType);
if (displayModeConfigAttributeMap != null) {
Map<String, T> configAttributeMap = (Map<String, T>) displayModeConfigAttributeMap.get(displayMode);
if (configAttributeMap != null) {
configAttributeMap.remove(configLabel);
}
}
}
// Display mode ordering //////////////////////////////////////////////////
IDisplayModeOrdering displayModeOrdering = new DefaultDisplayModeOrdering();
public IDisplayModeOrdering getDisplayModeOrdering() {
return displayModeOrdering;
}
public void setDisplayModeOrdering(IDisplayModeOrdering displayModeOrdering) {
this.displayModeOrdering = displayModeOrdering;
}
// Private methods
}
| 4,652 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultComparator.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/DefaultComparator.java | package net.sourceforge.nattable.config;
import java.util.Comparator;
@SuppressWarnings("unchecked")
public class DefaultComparator implements Comparator<Object> {
private static DefaultComparator singleton;
public static final DefaultComparator getInstance() {
if (singleton == null) {
singleton = new DefaultComparator();
}
return singleton;
}
public int compare(final Object o1, final Object o2) {
if (o1 == null) {
if (o2 == null) {
return 0;
} else {
return -1;
}
} else if (o2 == null) {
return 1;
} else if (o1 instanceof Comparable && o2 instanceof Comparable) {
return ((Comparable) o1).compareTo((Comparable) o2);
} else {
return 0;
}
}
}
| 738 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractLayerConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/AbstractLayerConfiguration.java | package net.sourceforge.nattable.config;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
/**
* Casts the layer to be to the type parameter for convenience.
* @param <L> type of the layer being configured
*/
public abstract class AbstractLayerConfiguration<L extends ILayer> implements IConfiguration {
@SuppressWarnings("unchecked")
public void configureLayer(ILayer layer) {
configureTypedLayer((L) layer);
}
public abstract void configureTypedLayer(L layer);
public void configureRegistry(IConfigRegistry configRegistry) {}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {}
}
| 706 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
AbstractRegistryConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/AbstractRegistryConfiguration.java | package net.sourceforge.nattable.config;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
public abstract class AbstractRegistryConfiguration implements IConfiguration {
public void configureLayer(ILayer layer) {}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {}
}
| 367 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultNatTableStyleConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/DefaultNatTableStyleConfiguration.java | package net.sourceforge.nattable.config;
import net.sourceforge.nattable.data.convert.DefaultDisplayConverter;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.painter.cell.TextPainter;
import net.sourceforge.nattable.painter.cell.decorator.LineBorderDecorator;
import net.sourceforge.nattable.style.BorderStyle;
import net.sourceforge.nattable.style.CellStyleAttributes;
import net.sourceforge.nattable.style.HorizontalAlignmentEnum;
import net.sourceforge.nattable.style.Style;
import net.sourceforge.nattable.style.VerticalAlignmentEnum;
import net.sourceforge.nattable.util.GUIHelper;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
public class DefaultNatTableStyleConfiguration extends AbstractRegistryConfiguration {
public Color bgColor = GUIHelper.COLOR_WHITE;
public Color fgColor = GUIHelper.COLOR_BLACK;
public Font font = GUIHelper.DEFAULT_FONT;
public HorizontalAlignmentEnum hAlign = HorizontalAlignmentEnum.CENTER;
public VerticalAlignmentEnum vAlign = VerticalAlignmentEnum.MIDDLE;
public BorderStyle borderStyle = null;
public ICellPainter cellPainter = new LineBorderDecorator(new TextPainter());
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter);
Style cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, bgColor);
cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, fgColor);
cellStyle.setAttributeValue(CellStyleAttributes.FONT, font);
cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, hAlign);
cellStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, vAlign);
cellStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, borderStyle);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle);
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultDisplayConverter());
}
}
| 2,099 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultEditableRule.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/DefaultEditableRule.java | package net.sourceforge.nattable.config;
public class DefaultEditableRule implements IEditableRule {
private boolean defaultEditable;
public DefaultEditableRule(boolean defaultEditable) {
this.defaultEditable = defaultEditable;
}
public boolean isEditable(int columnIndex, int rowIndex) {
return defaultEditable;
}
}
| 348 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
CellConfigAttributes.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/CellConfigAttributes.java | package net.sourceforge.nattable.config;
import net.sourceforge.nattable.data.convert.IDisplayConverter;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.style.ConfigAttribute;
import net.sourceforge.nattable.style.IStyle;
public interface CellConfigAttributes {
public static final ConfigAttribute<ICellPainter> CELL_PAINTER = new ConfigAttribute<ICellPainter>();
public static final ConfigAttribute<IStyle> CELL_STYLE = new ConfigAttribute<IStyle>();
public static final ConfigAttribute<IDisplayConverter> DISPLAY_CONVERTER = new ConfigAttribute<IDisplayConverter>();
}
| 626 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IConfigRegistry.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/IConfigRegistry.java | package net.sourceforge.nattable.config;
import java.util.List;
import net.sourceforge.nattable.style.ConfigAttribute;
import net.sourceforge.nattable.style.DisplayMode;
import net.sourceforge.nattable.style.IDisplayModeOrdering;
/**
* Holds all the settings, bindings and other configuration for NatTable.</br>
*
* @see ConfigRegistry
* @see ConfigRegistryTest for a better understanding
*/
public interface IConfigRegistry {
/**
* If retrieving registered values<br/>
* Example 1:<br/>
* configRegistry.getConfigAttribute(attribute, DisplayMode.EDIT);<br/>
* <ol>
* <li>It will look for an attribute registered using the EDIT display mode</li>
* <li>If it can't find that it will try and find an attribute under the NORMAL mode</li>
* <li>If it can't find one it will try and find one registered without a display mode {@link #registerConfigAttribute(ConfigAttribute, Object)}</li>
* </ol>
* Example 2:<br/>
* configRegistry.getConfigAttribute(attribute, DisplayMode.NORMAL, "testLabel", "testLabel_1");<br/>
* <ol>
* <li>It will look for an attribute registered by display mode NORMAL and "testLabel"<li/>
* <li>It will look for an attribute registered by display mode NORMAL and "testLabel_1"<li/>
* </ol>
* @param <T> Type of the attribute
* @param configAttribute to be registered
* @param targetDisplayMode display mode the cell needs to be in, for this attribute to be returned
* @param configLabels the cell needs to have, for this attribute to be returned
* @return the configAttribute, if the display mode and the configLabels match
*/
public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode, String...configLabels);
/**
* @see #getConfigAttribute(ConfigAttribute, String, String...)
*/
public <T> T getConfigAttribute(ConfigAttribute<T> configAttribute, String targetDisplayMode, List<String> configLabels);
/**
* @see #getConfigAttribute(ConfigAttribute, String, String...)
*/
public <T> T getSpecificConfigAttribute(ConfigAttribute<T> configAttribute, String displayMode, String configLabel);
/**
* Register a configuration attribute
*/
public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue);
/**
* Register an attribute against a {@link DisplayMode}.
*/
public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue, String targetDisplayMode);
/**
* Register an attribute against a {@link DisplayMode} and configuration label (applied to cells)
*/
public <T> void registerConfigAttribute(ConfigAttribute<T> configAttribute, T attributeValue, String targetDisplayMode, String configLabel);
public <T> void unregisterConfigAttribute(Class<T> configAttributeType, String displayMode, String configLabel);
public IDisplayModeOrdering getDisplayModeOrdering();
}
| 2,947 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
IEditableRule.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/config/IEditableRule.java | package net.sourceforge.nattable.config;
public interface IEditableRule {
public boolean isEditable(int columnIndex, int rowIndex);
public static final IEditableRule ALWAYS_EDITABLE = new IEditableRule() {
public boolean isEditable(int columnIndex, int rowIndex) {
return true;
}
};
public static final IEditableRule NEVER_EDITABLE = new IEditableRule() {
public boolean isEditable(int columnIndex, int rowIndex) {
return false;
}
};
}
| 494 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SortConfigAttributes.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/SortConfigAttributes.java | package net.sourceforge.nattable.sort;
import java.util.Comparator;
import net.sourceforge.nattable.style.ConfigAttribute;
public interface SortConfigAttributes {
public static final ConfigAttribute<Comparator<?>> SORT_COMPARATOR = new ConfigAttribute<Comparator<?>>();
}
| 279 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
ISortModel.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/ISortModel.java | package net.sourceforge.nattable.sort;
import net.sourceforge.nattable.sort.command.SortCommandHandler;
/**
* Interface providing sorting functionality.
*/
public interface ISortModel {
/**
* @return TRUE if the column with the given index is sorted at the moment.
*/
public boolean isColumnIndexSorted(int columnIndex);
/**
* @return the direction in which the column with the given index is<br/>
* currently sorted
*/
public SortDirectionEnum getSortDirection(int columnIndex);
/**
* @return when multiple columns are sorted, this returns the order of the<br/>
* column index in the sort<br/>
*
* Example: If column indexes 3, 6, 9 are sorted (in that order) the sort order<br/>
* for index 6 is 1.
*/
public int getSortOrder(int columnIndex);
/**
* This method is called by the {@link SortCommandHandler} in response to a sort command.<br/>
* It is responsible for sorting the requested column. <br/>
*
* @param accumulate flag indicating if the column should added to a previous sort.
*/
public void sort(int columnIndex, SortDirectionEnum sortDirection, boolean accumulate);
/**
* Remove all sorting
*/
public void clear();
}
| 1,187 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SortDirectionEnum.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/SortDirectionEnum.java | package net.sourceforge.nattable.sort;
public enum SortDirectionEnum {
ASC("Ascending"), DESC("Ascending"), NONE("Unsorted");
private final String description;
private SortDirectionEnum(String description) {
this.description = description;
}
/**
* @return the sorting state to go to from the current one.
*/
public SortDirectionEnum getNextSortDirection() {
switch (this) {
case NONE:
return SortDirectionEnum.ASC;
case ASC:
return SortDirectionEnum.DESC;
case DESC:
return SortDirectionEnum.NONE;
default:
return SortDirectionEnum.NONE;
}
}
public String getDescription() {
return description;
}
} | 674 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SortStatePersistor.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/SortStatePersistor.java | package net.sourceforge.nattable.sort;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Properties;
import net.sourceforge.nattable.persistence.IPersistable;
/**
* Handles persisting of the sorting state.<br/>
* The sorting state is read from and restored to the {@link ISortModel}.<br/>
*
* @param <T> Type of the Beans in the backing data source.
*/
public class SortStatePersistor<T> implements IPersistable {
public static final String PERSISTENCE_KEY_SORTING_STATE = ".SortHeaderLayer.sortingState";
private final SortHeaderLayer<T> sortHeaderLayer;
private final ISortModel sortModel;
public SortStatePersistor(SortHeaderLayer<T> sortHeaderLayer) {
this.sortHeaderLayer = sortHeaderLayer;
this.sortModel = sortHeaderLayer.getSortModel();
}
/**
* Save the sorting state in the properties file.<br/>
* Key:
* {@link #PERSISTENCE_KEY_SORTING_STATE}<br/>
*
* Format:<br/>
* column index : sort direction : sort order |
*/
public void saveState(String prefix, Properties properties) {
int columnCount = sortHeaderLayer.getColumnCount();
StringBuffer buffer = new StringBuffer();
for (int columnPosition = 0; columnPosition < columnCount; columnPosition++) {
int columnIndex = sortHeaderLayer.getColumnIndexByPosition(columnPosition);
boolean isColumnSorted = sortModel.isColumnIndexSorted(columnIndex);
if (isColumnSorted) {
SortDirectionEnum sortDirection = sortModel.getSortDirection(columnIndex);
int sortOrder = sortModel.getSortOrder(columnIndex);
buffer.append(columnIndex);
buffer.append(":");
buffer.append(sortDirection.toString());
buffer.append(":");
buffer.append(sortOrder);
buffer.append("|");
}
}
if (isNotEmpty(buffer.toString())) {
properties.put(prefix + PERSISTENCE_KEY_SORTING_STATE, buffer.toString());
}
}
/**
* Parses the saved string and restores the state to the {@link ISortModel}.
*/
public void loadState(String prefix, Properties properties) {
Object savedValue = properties.get(prefix + PERSISTENCE_KEY_SORTING_STATE);
if(savedValue == null){
return;
}
try{
String savedState = savedValue.toString();
String[] sortedColumns = savedState.split("\\|");
List<SortState> stateInfo = new ArrayList<SortState>();
// Parse string
for (String token : sortedColumns) {
stateInfo.add(getSortStateFromString(token));
}
// Order by the sort order
Collections.sort(stateInfo, new SortStateComparator());
// Restore to the model
for (SortState state : stateInfo) {
sortModel.sort(state.columnIndex, state.sortDirection, true);
}
}catch(Exception ex){
sortModel.clear();
System.err.println("Error while restoring sorting state. Skipping");
ex.printStackTrace(System.err);
}
}
/**
* Parse the string representation to extract the
* column index, sort direction and sort order
*/
protected SortState getSortStateFromString(String token) {
String[] split = token.split(":");
int columnIndex = Integer.parseInt(split[0]);
SortDirectionEnum sortDirection = SortDirectionEnum.valueOf(split[1]);
int sortOrder = Integer.parseInt(split[2]);
return new SortState(columnIndex, sortDirection, sortOrder);
}
/**
* Encapsulation of the sort state of a column
*/
protected class SortState {
public int columnIndex;
public SortDirectionEnum sortDirection;
public int sortOrder;
public SortState(int columnIndex, SortDirectionEnum sortDirection, int sortOrder) {
this.columnIndex = columnIndex;
this.sortDirection = sortDirection;
this.sortOrder = sortOrder;
}
}
/**
* Helper class to order sorting state by the 'sort order'.
* The sorting state has be restored in the same sequence
* in which the original sort was applied.
*/
private class SortStateComparator implements Comparator<SortState> {
public int compare(SortState state1, SortState state2) {
return Integer.valueOf(state1.sortOrder).compareTo(Integer.valueOf(state2.sortOrder));
}
}
}
| 4,268 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SortHeaderLayer.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/SortHeaderLayer.java | package net.sourceforge.nattable.sort;
import net.sourceforge.nattable.layer.AbstractLayerTransform;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.layer.LabelStack;
import net.sourceforge.nattable.persistence.IPersistable;
import net.sourceforge.nattable.sort.command.SortCommandHandler;
import net.sourceforge.nattable.sort.config.DefaultSortConfiguration;
/**
* Enables sorting of the data. Uses an {@link ISortModel} to do/track the sorting.
* @param <T> Type of the Beans in the backing data source.
*
* @see DefaultSortConfiguration
* @see SortStatePersistor
*/
public class SortHeaderLayer<T> extends AbstractLayerTransform implements IPersistable {
/** Handles the actual sorting of underlying data */
private final ISortModel sortModel;
public SortHeaderLayer(ILayer underlyingLayer, ISortModel sortModel) {
this(underlyingLayer, sortModel, true);
}
public SortHeaderLayer(ILayer underlyingLayer, ISortModel sortModel, boolean useDefaultConfiguration) {
super(underlyingLayer);
this.sortModel = sortModel;
registerPersistable(new SortStatePersistor<T>(this));
registerCommandHandler(new SortCommandHandler<T>(sortModel, this));
if (useDefaultConfiguration) {
addConfiguration(new DefaultSortConfiguration());
}
}
/**
* @return adds a special configuration label to the stack taking into account the following:<br/>
* <ol>
* <li>Is the column sorted ?</li>
* <li>What is the sort order of the column</li>
* </ol>
* A special painter is registered against the above labels to render the sort arrows
*/
@Override
public LabelStack getConfigLabelsByPosition(int columnPosition, int rowPosition) {
LabelStack configLabels = super.getConfigLabelsByPosition(columnPosition, rowPosition);
if (sortModel != null) {
int columnIndex = getColumnIndexByPosition(columnPosition);
if (sortModel.isColumnIndexSorted(columnIndex)) {
SortDirectionEnum sortDirection = sortModel.getSortDirection(columnIndex);
switch (sortDirection) {
case ASC:
configLabels.addLabel(DefaultSortConfiguration.SORT_UP_CONFIG_TYPE);
break;
case DESC:
configLabels.addLabel(DefaultSortConfiguration.SORT_DOWN_CONFIG_TYPE);
break;
}
String sortConfig = DefaultSortConfiguration.SORT_SEQ_CONFIG_TYPE + sortModel.getSortOrder(columnIndex);
configLabels.addLabel(sortConfig);
}
}
return configLabels;
}
protected ISortModel getSortModel() {
return sortModel;
}
} | 2,567 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SortColumnAction.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/action/SortColumnAction.java | package net.sourceforge.nattable.sort.action;
import net.sourceforge.nattable.NatTable;
import net.sourceforge.nattable.sort.command.SortColumnCommand;
import net.sourceforge.nattable.ui.NatEventData;
import net.sourceforge.nattable.ui.action.IMouseAction;
import org.eclipse.swt.events.MouseEvent;
public class SortColumnAction implements IMouseAction {
private final boolean accumulate;
public SortColumnAction(boolean accumulate) {
this.accumulate = accumulate;
}
public void run(NatTable natTable, MouseEvent event) {
int columnPosition = ((NatEventData)event.data).getColumnPosition();
natTable.doCommand(new SortColumnCommand(natTable, columnPosition, accumulate));
}
}
| 717 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SingleClickSortConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/config/SingleClickSortConfiguration.java | package net.sourceforge.nattable.sort.config;
import net.sourceforge.nattable.sort.action.SortColumnAction;
import net.sourceforge.nattable.sort.event.ColumnHeaderClickEventMatcher;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.MouseEventMatcher;
import org.eclipse.swt.SWT;
/**
* Modifies the default sort configuration to sort on a <i>single left</i> <br/>
* click on the column header.
*/
public class SingleClickSortConfiguration extends DefaultSortConfiguration {
/**
* Remove the original key bindings and implement new ones.
*/
@Override
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
// Register new bindings
uiBindingRegistry.registerFirstSingleClickBinding(
new ColumnHeaderClickEventMatcher(SWT.NONE, 1), new SortColumnAction(false));
uiBindingRegistry.registerSingleClickBinding(
MouseEventMatcher.columnHeaderLeftClick(SWT.ALT), new SortColumnAction(true));
}
}
| 1,037 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
DefaultSortConfiguration.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/config/DefaultSortConfiguration.java | package net.sourceforge.nattable.sort.config;
import net.sourceforge.nattable.config.CellConfigAttributes;
import net.sourceforge.nattable.config.DefaultComparator;
import net.sourceforge.nattable.config.IConfigRegistry;
import net.sourceforge.nattable.config.IConfiguration;
import net.sourceforge.nattable.grid.GridRegion;
import net.sourceforge.nattable.layer.ILayer;
import net.sourceforge.nattable.painter.cell.ICellPainter;
import net.sourceforge.nattable.painter.cell.decorator.BeveledBorderDecorator;
import net.sourceforge.nattable.sort.SortConfigAttributes;
import net.sourceforge.nattable.sort.action.SortColumnAction;
import net.sourceforge.nattable.sort.painter.SortableHeaderTextPainter;
import net.sourceforge.nattable.style.DisplayMode;
import net.sourceforge.nattable.ui.binding.UiBindingRegistry;
import net.sourceforge.nattable.ui.matcher.MouseEventMatcher;
import org.eclipse.swt.SWT;
public class DefaultSortConfiguration implements IConfiguration {
public static final String SORT_DOWN_CONFIG_TYPE = "SORT_DOWN";
public static final String SORT_UP_CONFIG_TYPE = "SORT_UP";
/** The sort sequence can be appended to this base */
public static final String SORT_SEQ_CONFIG_TYPE = "SORT_SEQ_";
public void configureLayer(ILayer layer) {}
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, new DefaultComparator());
ICellPainter sortableHeaderCellPainter = new BeveledBorderDecorator(new SortableHeaderTextPainter());
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortableHeaderCellPainter, DisplayMode.NORMAL, SORT_DOWN_CONFIG_TYPE);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, sortableHeaderCellPainter, DisplayMode.NORMAL, SORT_UP_CONFIG_TYPE);
}
public void configureUiBindings(UiBindingRegistry uiBindingRegistry) {
uiBindingRegistry.registerSingleClickBinding(
new MouseEventMatcher(SWT.ALT, GridRegion.COLUMN_HEADER.toString(), 1), new SortColumnAction(false));
uiBindingRegistry.registerSingleClickBinding(
new MouseEventMatcher(SWT.ALT | SWT.SHIFT, GridRegion.COLUMN_HEADER.toString(), 1), new SortColumnAction(true));
}
}
| 2,292 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
SortCommandHandler.java | /FileExtraction/Java_unseen/heartsome_translationstudio8/others/net.sourceforge.nattable.core/src/net/sourceforge/nattable/sort/command/SortCommandHandler.java | package net.sourceforge.nattable.sort.command;
import net.sourceforge.nattable.command.AbstractLayerCommandHandler;
import net.sourceforge.nattable.sort.ISortModel;
import net.sourceforge.nattable.sort.SortDirectionEnum;
import net.sourceforge.nattable.sort.SortHeaderLayer;
import net.sourceforge.nattable.sort.event.SortColumnEvent;
import org.eclipse.swt.custom.BusyIndicator;
/**
* Handle sort commands
*/
public class SortCommandHandler<T> extends AbstractLayerCommandHandler<SortColumnCommand> {
private final ISortModel sortModel;
private final SortHeaderLayer<T> sortHeaderLayer;
public SortCommandHandler(ISortModel sortModel, SortHeaderLayer<T> sortHeaderLayer) {
this.sortModel = sortModel;
this.sortHeaderLayer = sortHeaderLayer;
}
@Override
public boolean doCommand(final SortColumnCommand command) {
final int columnIndex = command.getLayer().getColumnIndexByPosition(command.getColumnPosition());
final SortDirectionEnum newSortDirection = sortModel.getSortDirection(columnIndex).getNextSortDirection();
// Fire command - with busy indicator
Runnable sortRunner = new Runnable() {
public void run() {
sortModel.sort(columnIndex, newSortDirection, command.isAccumulate());
}
};
BusyIndicator.showWhile(null, sortRunner);
// Fire event
SortColumnEvent sortEvent = new SortColumnEvent(sortHeaderLayer, command.getColumnPosition());
sortHeaderLayer.fireLayerEvent(sortEvent);
return true;
}
public Class<SortColumnCommand> getCommandClass() {
return SortColumnCommand.class;
}
} | 1,596 | Java | .java | heartsome/translationstudio8 | 83 | 45 | 18 | 2014-06-03T17:56:15Z | 2020-10-13T06:46:15Z |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.