use of net.heartsome.cat.ts.ui.grid.GridCopyEnable in project translationstudio8 by heartsome.
the class MatchViewPart method createPartControl.
@Override
public void createPartControl(Composite parent) {
GridLayout parentGl = new GridLayout(1, false);
parentGl.marginWidth = 0;
parentGl.marginHeight = 0;
parent.setLayout(parentGl);
final Composite composite = new Composite(parent, SWT.NONE);
GridLayout compositeGl = new GridLayout(1, false);
compositeGl.marginBottom = -1;
compositeGl.marginLeft = -1;
compositeGl.marginRight = -1;
compositeGl.marginTop = 0;
compositeGl.marginWidth = 0;
compositeGl.marginHeight = 0;
compositeGl.verticalSpacing = 0;
composite.setLayout(compositeGl);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// sourceText = new StyledText(composite, SWT.BORDER | SWT.V_SCROLL | SWT.READ_ONLY);
// GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
// Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
// sourceText.setFont(f);
// int lineH = sourceText.getLineHeight() * 3;
// sTextGd.heightHint = lineH;
// sTextGd.minimumHeight = lineH;
// sourceText.setLayoutData(sTextGd);
SashForm sashForm = new SashForm(composite, SWT.VERTICAL);
sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
sourceText = new SegmentViewer(sashForm, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.READ_ONLY | SWT.V_SCROLL, null);
StyledText srcTextControl = sourceText.getTextWidget();
srcTextControl.setLineSpacing(net.heartsome.cat.ts.ui.Constants.SEGMENT_LINE_SPACING);
srcTextControl.setLeftMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_LEFT_MARGIN);
srcTextControl.setRightMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_RIGHT_MARGIN);
srcTextControl.setTopMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
srcTextControl.setBottomMargin(net.heartsome.cat.ts.ui.Constants.SEGMENT_TOP_MARGIN);
srcTextControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
sourceText.setSource("");
sourceColunmCellRenderer.setSegmentViewer(sourceText);
GridData sTextGd = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
Font f = JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT);
srcTextControl.setFont(f);
int lineH = srcTextControl.getLineHeight() * 2;
sTextGd.heightHint = lineH;
sTextGd.minimumHeight = lineH;
srcTextControl.setLayoutData(sTextGd);
net.heartsome.cat.ts.ui.innertag.tagstyle.TagStyleConfigurator.configure(sourceText);
gridTable = new Grid(sashForm, SWT.BORDER | SWT.V_SCROLL);
gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
gridTable.setHeaderVisible(false);
gridTable.setAutoHeight(true);
gridTable.setRowsResizeable(true);
gridTable.setData("selectedBgColor", selectedBgColor);
final GridColumn sourceCln = new GridColumn(gridTable, SWT.NONE);
sourceColunmCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
sourceCln.setCellRenderer(sourceColunmCellRenderer);
sourceCln.setText(Messages.getString("view.MatchViewPart.sourceCln"));
sourceCln.setWordWrap(true);
sourceCln.setAlignment(SWT.CENTER);
sourceCln.setResizeable(false);
final GridColumn typeCln = new GridColumn(gridTable, SWT.NONE);
typeColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
typeCln.setCellRenderer(typeColumnCellRenderer);
typeCln.setText(Messages.getString("view.MatchViewPart.typeCln"));
typeCln.setWordWrap(true);
typeCln.setAlignment(SWT.CENTER);
typeCln.setResizeable(false);
final GridColumn targetCln = new GridColumn(gridTable, SWT.NONE);
targetColumnCellRenderer.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.MATCH_VIEWER_TEXT_FONT));
targetCln.setCellRenderer(targetColumnCellRenderer);
targetCln.setText(Messages.getString("view.MatchViewPart.targetCln"));
targetCln.setWordWrap(true);
targetCln.setAlignment(SWT.CENTER);
targetCln.setResizeable(false);
// 设置可复制功能
copyEnable = new GridCopyEnable(gridTable);
sourceColunmCellRenderer.setCopyEnable(copyEnable);
targetColumnCellRenderer.setCopyEnable(copyEnable);
Composite statusComposite = new Composite(composite, SWT.NONE);
GridLayout statusComptGridLayout = new GridLayout(2, false);
statusComptGridLayout.marginBottom = -1;
statusComptGridLayout.marginLeft = -1;
statusComptGridLayout.marginRight = -1;
statusComptGridLayout.marginTop = -1;
statusComptGridLayout.marginWidth = 0;
statusComptGridLayout.marginHeight = 0;
statusComposite.setLayout(statusComptGridLayout);
statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tipLabel = new CLabel(statusComposite, SWT.NONE);
tipLabel.setAlignment(SWT.LEFT);
infoLabel = new CLabel(statusComposite, SWT.NONE);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
gd.heightHint = 20;
infoLabel.setLayoutData(gd);
infoLabel.setAlignment(SWT.RIGHT);
// 设置列宽按比例4.5:1:4.5
composite.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle area = composite.getClientArea();
Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// - 2 * gridTable.getBorderWidth();
int width = area.width;
if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
Point vBarSize = gridTable.getVerticalBar().getSize();
width -= vBarSize.x;
}
gridTable.setSize(area.width, area.height);
width = width - 42;
sourceCln.setWidth((int) (width * 0.5));
typeCln.setWidth(42);
targetCln.setWidth((int) (width * 0.5));
}
});
gridTable.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
StyledText text = sourceText.getTextWidget();
text.setText(text.getText());
updateActionState();
GridItem[] selItems = gridTable.getSelection();
if (selItems.length != 1) {
return;
}
GridItem item = selItems[0];
setMatchMessage(infoLabelImage, item.getData("info").toString(), item.getData("infoTooltip").toString());
composite.layout();
}
});
gridTable.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
menuMgr.acceptMatchAction.run();
}
});
createActions();
sashForm.setWeights(new int[] { 3, 8 });
}
use of net.heartsome.cat.ts.ui.grid.GridCopyEnable in project translationstudio8 by heartsome.
the class TerminologyViewPart method createPartControl.
/**
* 创建控件。
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
this.parent = parent;
createAction();
GridLayout parentGl = new GridLayout(1, false);
parentGl.marginWidth = 0;
parentGl.marginHeight = 0;
parent.setLayout(parentGl);
final Composite contentPanel = new Composite(parent, SWT.NONE);
GridLayout secondPageCompositeGl = new GridLayout(1, false);
secondPageCompositeGl.marginBottom = -1;
secondPageCompositeGl.marginLeft = -1;
secondPageCompositeGl.marginRight = -1;
secondPageCompositeGl.marginTop = -1;
secondPageCompositeGl.marginWidth = 0;
secondPageCompositeGl.marginHeight = 0;
contentPanel.setLayout(secondPageCompositeGl);
contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
contentPanel.setLayout(secondPageCompositeGl);
contentPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
// firstPageComposite = new Composite(contentPanel, SWT.NONE);
// firstPageComposite.setLayout(new GridLayout(1, false));
// secondPageComposite = new Composite(contentPanel, SWT.NONE);
// GridLayout secondPageCompositeGl = new GridLayout(1, false);
// secondPageCompositeGl.marginBottom = -1;
// secondPageCompositeGl.marginLeft = -1;
// secondPageCompositeGl.marginRight = -1;
// secondPageCompositeGl.marginTop = -1;
// secondPageCompositeGl.marginWidth = 0;
// secondPageCompositeGl.marginHeight = 0;
// secondPageComposite.setLayout(secondPageCompositeGl);
// secondPageComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
gridTable = new Grid(contentPanel, SWT.BORDER | SWT.V_SCROLL);
gridTable.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
gridTable.setHeaderVisible(true);
gridTable.setAutoHeight(true);
gridTable.setRowsResizeable(true);
gridTable.setData("selectedBgColor", selectedBgColor);
final GridColumn idItem = new GridColumn(gridTable, SWT.NONE);
idItem.setText(Messages.getString("view.TerminologyViewPart.idItem"));
idColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
idColumnCellRenderer.setVerticalAlignment(SWT.CENTER);
idItem.setCellRenderer(idColumnCellRenderer);
idItem.setWordWrap(true);
srcTableColumn = new GridColumn(gridTable, SWT.NONE);
srcTableColumn.setText(Messages.getString("view.TerminologyViewPart.srcTableColumn"));
srcColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
srcTableColumn.setCellRenderer(srcColumnCellRenderer);
srcTableColumn.setWordWrap(true);
tgtTableColumn = new GridColumn(gridTable, SWT.NONE);
tgtTableColumn.setText(Messages.getString("view.TerminologyViewPart.tgtTableColumn"));
tgtColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
tgtTableColumn.setCellRenderer(tgtColumnCellRenderer);
tgtTableColumn.setWordWrap(true);
final GridColumn propertyColumn = new GridColumn(gridTable, SWT.NONE);
propertyColumn.setText(Messages.getString("view.TerminologyViewPart.propertyColumn"));
propColumnCellRenderer.setFont(JFaceResources.getFont(Constants.MATCH_VIEWER_TEXT_FONT));
propertyColumn.setCellRenderer(propColumnCellRenderer);
propertyColumn.setWordWrap(true);
copyEnable = new GridCopyEnable(gridTable);
srcColumnCellRenderer.setCopyEnable(copyEnable);
tgtColumnCellRenderer.setCopyEnable(copyEnable);
// 设置列宽按比例
contentPanel.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
Rectangle area = contentPanel.getClientArea();
Point preferredSize = gridTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
// - 2 * gridTable.getBorderWidth();
int width = area.width;
if (preferredSize.y > area.height + gridTable.getHeaderHeight()) {
Point vBarSize = gridTable.getVerticalBar().getSize();
width -= vBarSize.x;
}
gridTable.setSize(area.width, area.height);
width -= 45;
idItem.setWidth(45);
srcTableColumn.setWidth((int) (width * 0.4));
tgtTableColumn.setWidth((int) (width * 0.4));
propertyColumn.setWidth((int) (width * 0.2));
}
});
Composite statusComposite = new Composite(contentPanel, SWT.NONE);
GridLayout statusComptGridLayout = new GridLayout(2, false);
statusComptGridLayout.marginBottom = -1;
statusComptGridLayout.marginLeft = -1;
statusComptGridLayout.marginRight = -1;
statusComptGridLayout.marginTop = -1;
statusComptGridLayout.marginWidth = 0;
statusComptGridLayout.marginHeight = 0;
statusComposite.setLayout(statusComptGridLayout);
statusComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tipLabel = new CLabel(statusComposite, SWT.NONE);
tipLabel.setAlignment(SWT.LEFT);
CLabel label = new CLabel(statusComposite, SWT.None);
GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
gd.heightHint = 20;
label.setLayoutData(gd);
gridTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
selectItem();
}
});
gridTable.addListener(SWT.MouseDoubleClick, new Listener() {
public void handleEvent(Event event) {
firstAction.run();
}
});
initHookMenu();
}
Aggregations