use of org.talend.dataprofiler.core.service.IAntlrEditorUIService in project tdq-studio-se by Talend.
the class ParserRuleMasterDetailsPage method createButtons.
/**
* DOC klliu Comment method "createButtons".
*
* @param parent
*/
private void createButtons(Composite parent, final ParserRuleTableViewer parserRuleTableViewer) {
boolean isNeedTestButton = false;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IAntlrEditorUIService.class)) {
isNeedTestButton = true;
}
Composite buttonsComposite = new Composite(parent, SWT.NONE);
buttonsComposite.setLayout(new GridLayout(7, true));
GridData labelGd = new GridData();
labelGd.horizontalAlignment = SWT.LEFT;
labelGd.widthHint = 30;
final Button addButton = new Button(buttonsComposite, SWT.NONE);
// $NON-NLS-1$
addButton.setToolTipText("Add New Item");
addButton.setImage(ImageLib.getImage(ImageLib.ADD_ACTION));
addButton.setLayoutData(labelGd);
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
parserRuleTableViewer.addTdExpression();
}
});
final Button delButton = new Button(buttonsComposite, SWT.NONE);
// $NON-NLS-1$
delButton.setToolTipText("Delete Selcetion Item");
delButton.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
delButton.setLayoutData(labelGd);
delButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TdExpression tdExpression = (TdExpression) ((IStructuredSelection) parserRuleTableViewer.getSelection()).getFirstElement();
if (tdExpression != null) {
parserRuleTableViewer.removeTdExpression(tdExpression);
}
}
});
final Button upButton = new Button(buttonsComposite, SWT.NONE);
// $NON-NLS-1$
upButton.setToolTipText("Move Item Up");
upButton.setImage(ImageLib.getImage(ImageLib.UP_ACTION));
upButton.setLayoutData(labelGd);
upButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TdExpression tdExpression = (TdExpression) ((IStructuredSelection) parserRuleTableViewer.getSelection()).getFirstElement();
if (tdExpression != null) {
parserRuleTableViewer.moveTdExpression(tdExpression, 1);
}
}
});
final Button downButton = new Button(buttonsComposite, SWT.NONE);
// $NON-NLS-1$
downButton.setToolTipText("Move Item Down");
downButton.setImage(ImageLib.getImage(ImageLib.DOWN_ACTION));
downButton.setLayoutData(labelGd);
downButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TdExpression tdExpression = (TdExpression) ((IStructuredSelection) parserRuleTableViewer.getSelection()).getFirstElement();
if (tdExpression != null) {
parserRuleTableViewer.moveTdExpression(tdExpression, -1);
}
}
});
final Button copyButton = new Button(buttonsComposite, SWT.NONE);
// $NON-NLS-1$
copyButton.setToolTipText("Copy Selcetion Item");
copyButton.setImage(ImageLib.getImage(ImageLib.COPY_ACTION));
copyButton.setLayoutData(labelGd);
copyButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
List<TdExpression> listTdExpression = ((IStructuredSelection) parserRuleTableViewer.getSelection()).toList();
parserRuleTableViewer.copyTdExpression(listTdExpression);
}
});
final Button pasteButton = new Button(buttonsComposite, SWT.NONE);
// $NON-NLS-1$
pasteButton.setToolTipText("Paste Selcetion Item");
pasteButton.setImage(ImageLib.getImage(ImageLib.PASTE_ACTION));
pasteButton.setLayoutData(labelGd);
pasteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
parserRuleTableViewer.pasteTdExpression();
}
});
if (isNeedTestButton) {
final Button testButton = new Button(buttonsComposite, SWT.NONE);
testButton.setImage(ImageLib.getImage(ImageLib.RULE_TEST));
// $NON-NLS-1$
testButton.setToolTipText(DefaultMessagesImpl.getString("ParserRuleMasterDetailsPage.testRule"));
testButton.setLayoutData(labelGd);
testButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IAntlrEditorUIService.class)) {
IAntlrEditorUIService antlrEditorUIService = (IAntlrEditorUIService) GlobalServiceRegister.getDefault().getService(IAntlrEditorUIService.class);
antlrEditorUIService.runTestRuleAction(getCurrentModelElement(), ParserRuleMasterDetailsPage.this.getEditor());
}
}
});
}
}
Aggregations