use of org.eclipse.jface.dialogs.IInputValidator in project tdq-studio-se by Talend.
the class TOPRepositoryService method getInputDialog.
/**
* Comment method "getInputDialog".
*
* @param get input dialog
* @return inputDialog
*/
public InputDialog getInputDialog(final Item newItem) {
Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// $NON-NLS-1$
String dialogTitle = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Title");
// $NON-NLS-1$
String dialogMessage = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Message");
final InputDialog inputDialog = new InputDialog(parentShell, dialogTitle, dialogMessage, newItem.getProperty().getLabel() + DateUtils.formatTimeStamp(DateUtils.PATTERN_6, System.currentTimeMillis()), new IInputValidator() {
public String isValid(String newText) {
String returnStr = null;
Item item = newItem;
ERepositoryObjectType type = ERepositoryObjectType.getItemType(item);
// String pattern = RepositoryConstants.getPattern(type);
// $NON-NLS-1$
String pattern = "[_A-Za-z0-9-][a-zA-Z0-9\\\\.\\\\-_(), ]*";
boolean matches = Pattern.matches(pattern, newText);
boolean nameAvailable = false;
try {
List<IRepositoryViewObject> listExistingObjects = ProxyRepositoryFactory.getInstance().getAll(type, true, false);
nameAvailable = ProxyRepositoryFactory.getInstance().isNameAvailable(item, newText, listExistingObjects);
} catch (PersistenceException e) {
log.error(e, e);
return e.getMessage();
}
if (!matches) {
returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
"TOPRepositoryService.InputDialog.ErrorMessage1");
} else if (!nameAvailable) {
returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
"TOPRepositoryService.InputDialog.ErrorMessage2");
}
return returnStr;
}
});
return inputDialog;
}
use of org.eclipse.jface.dialogs.IInputValidator in project usbdm-eclipse-plugins by podonoghue.
the class OpenGdbConsoleHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
InputDialog dialog = new InputDialog(window.getShell(), "TTY Port Number", "Port number for TTY console", portNum, new IInputValidator() {
@Override
public String isValid(String arg0) {
try {
int num = Integer.parseInt(arg0);
if (num <= 0) {
return "Must not be zero";
}
if (num >= 65536) {
return "Too large";
}
} catch (Exception e) {
return "Invalid integer";
}
return null;
}
});
int rc = dialog.open();
if (rc != InputDialog.OK) {
return null;
}
portNum = dialog.getValue();
try {
MyConsoleInterface.startServer(Integer.parseInt(portNum));
} catch (Exception e) {
MessageBox mb = new MessageBox(window.getShell());
mb.setMessage(e.getMessage());
mb.setText("Error opening TTY");
mb.open();
}
return null;
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDPasteConceptAction method doAction.
@Override
public IStatus doAction() {
try {
conceptList = WorkbenchClipboard.getWorkbenchClipboard().getConcepts();
XSDFactory factory = XSDFactory.eINSTANCE;
if (!conceptList.isEmpty()) {
// List<String> concepts = new ArrayList<String>();
int index = 0;
for (Iterator<XSDElementDeclaration> it = conceptList.iterator(); it.hasNext(); ) {
if (conceptList.get(index).getSchema() != null) {
// concepts = Util.getConcepts(conceptList.get(index).getSchema());
typeList = Util.getTypeDefinition(conceptList.get(index).getSchema());
}
index++;
Object concept = it.next();
if (concept instanceof XSDElementDeclaration) {
// edit by ymli,fix the bug:0011523. let the element(simple or complex) can be pasted
// if (concepts.contains(((XSDElementDeclaration) concept).getName())) {
XSDElementDeclaration copy_concept = (XSDElementDeclaration) concept;
XSDElementDeclaration new_copy_concept = factory.createXSDElementDeclaration();
new_copy_concept = (XSDElementDeclaration) copy_concept.cloneConcreteComponent(true, false);
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDPasteConceptAction_CopyElement, Messages.XSDPasteConceptAction_DialogTip, Messages.bind(Messages.XSDPasteConceptAction_CopyOf, copy_concept.getName()), new IInputValidator() {
public String isValid(String newText) {
if ((newText == null) || "".equals(newText)) {
return Messages.XSDPasteConceptAction_NameCannNotbeEmpty;
}
EList<XSDElementDeclaration> list = schema.getElementDeclarations();
for (XSDElementDeclaration d : list) {
if (d.getName().equalsIgnoreCase(newText)) {
return Messages.XSDPasteConceptAction_EntityAlreadyExists;
}
}
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
new_copy_concept.setName(id.getValue());
for (int i = 0; i < new_copy_concept.getIdentityConstraintDefinitions().size(); i++) {
String name = new_copy_concept.getIdentityConstraintDefinitions().get(i).getName().replaceAll(copy_concept.getName(), new_copy_concept.getName());
new_copy_concept.getIdentityConstraintDefinitions().get(i).setName(name);
}
if (new_copy_concept.getAnonymousTypeDefinition() == null) {
XSDComplexTypeDefinition copyType = (XSDComplexTypeDefinition) copy_concept.getTypeDefinition().cloneConcreteComponent(true, false);
String originalName = copyType.getName();
// $NON-NLS-1$
String typeName = "Copy_of_" + originalName;
copyType.setName(typeName);
schema.getContents().add(copyType);
new_copy_concept.setTypeDefinition(copyType);
}
new_copy_concept.updateElement();
schema.getContents().add(new_copy_concept);
addAnnotationForXSDElementDeclaration(copy_concept, new_copy_concept);
}
}
Map<String, XSDTypeDefinition> typeDef = Util.getTypeDefinition(schema);
for (XSDTypeDefinition type : copyTypeSet) {
if (typeDef.containsKey(type.getName())) {
continue;
}
XSDTypeDefinition typedefinitionClone = null;
if (type instanceof XSDComplexTypeDefinition) {
typedefinitionClone = factory.createXSDComplexTypeDefinition();
typedefinitionClone = (XSDComplexTypeDefinition) type.cloneConcreteComponent(true, false);
schema.getContents().add(typedefinitionClone);
addAnnotationForComplexType((XSDComplexTypeDefinition) type, (XSDComplexTypeDefinition) typedefinitionClone);
} else if (type instanceof XSDSimpleTypeDefinition) {
schema.getContents().add((XSDSimpleTypeDefinition) type.cloneConcreteComponent(true, false));
}
}
schema.getElement();
// WSDataModel wsObject = (WSDataModel)
// (page.getXObject().getWsObject());
// wsObject.getXsdSchema();//.setXsdSchema(Util.nodeToString(
// schema.getDocument()));
/*
* String schema1 = ((XSDTreeContentProvider) page.getViewer()
* .getContentProvider()).getXSDSchemaAsString(); wsObject.setXsdSchema(schema1); XMLEditor
* xmleditor=((XObjectEditor)page.getEditor()).getXmlEditor(); xmleditor.refresh(page.getXObject());
*/
page.markDirty();
page.refresh();
// page.refreshData();
getOperationHistory();
WorkbenchClipboard.getWorkbenchClipboard().conceptsReset();
typeList.clear();
return Status.OK_STATUS;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 0) {
copyElements();
WorkbenchClipboard.getWorkbenchClipboard().particlesReset();
page.markDirty();
page.refresh();
// page.refreshData();
getOperationHistory();
return Status.OK_STATUS;
} else {
return Status.CANCEL_STATUS;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg1, e.getLocalizedMessage()));
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDSetAnnotationDocumentationAction method doAction.
public IStatus doAction() {
try {
IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();
XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent) selection.getFirstElement());
if (struc.getAnnotation() == null) {
throw new RuntimeException(Messages.bind(Messages.XSDSetXX_ExceptionInfo, selection.getFirstElement().getClass().getName()));
}
InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDSetXX_DialogTitle, Messages.XSDSetXX_DialogTip, struc.getDocumentation(), new IInputValidator() {
public String isValid(String newText) {
return null;
}
});
id.setBlockOnOpen(true);
int ret = id.open();
if (ret == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
// $NON-NLS-1$
struc.setDocumentation("".equals(id.getValue()) ? null : id.getValue());
if (struc.hasChanged()) {
page.refresh();
page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
page.markDirty();
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetXX_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.jface.dialogs.IInputValidator in project tmdm-studio-se by Talend.
the class XSDEditFacetAction method editMinLength.
// EditLength
private void editMinLength() {
XSDMinLengthFacet currentValue = std.getMinLengthFacet();
// $NON-NLS-1$
String stringValue = "0";
if (currentValue != null) {
stringValue = currentValue.getLexicalValue();
}
dialog = new InputDialog(page.getSite().getShell(), Messages.XSDEditFacetAction_DialogTitle4, Messages.XSDEditFacetAction_DialogTitle4Tip, stringValue == null ? "" : stringValue, new // $NON-NLS-1$
IInputValidator() {
public String isValid(String newText) {
int val;
try {
val = Integer.parseInt(newText);
} catch (Exception e) {
return Messages.XSDEditFacetAction_ValueMustBeXX;
}
if (val < 0) {
return Messages.XSDEditFacetAction_ValueMustBeXX;
}
return null;
}
});
dialog.setBlockOnOpen(true);
int ret = dialog.open();
if (ret == Dialog.CANCEL) {
return;
}
if (currentValue != null) {
std.getFacetContents().remove(currentValue);
}
int intValue = Integer.parseInt(((InputDialog) dialog).getValue());
if (intValue > 0) {
XSDMinLengthFacet f = (XSDSchemaBuildingTools.getXSDFactory()).createXSDMinLengthFacet();
// $NON-NLS-1$
f.setLexicalValue("" + intValue);
std.getFacetContents().add(f);
}
}
Aggregations