use of fr.gouv.mindef.safran.database.ui.wizards.scaffolding.newmodel.INewModelWizard in project InformationSystem by ObeoNetwork.
the class AbstractSpecifyEObjectPage method createControl.
/**
* Create contents of the wizard.
* @param parent
*/
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
setControl(container);
if (sourcePage == true) {
container.setLayout(new GridLayout(3, false));
} else {
container.setLayout(new GridLayout(4, false));
}
lblError = new Label(container, SWT.NONE);
lblError.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
if (sourcePage == true) {
lblError.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
} else {
lblError.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
}
Label lblFile = new Label(container, SWT.NONE);
lblFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblFile.setText("File :");
textModelFile = new Text(container, SWT.BORDER);
textModelFile.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Button btnBrowse = new Button(container, SWT.NONE);
btnBrowse.setText("Browse...");
if (sourcePage != true) {
Button btnNew = new Button(container, SWT.NONE);
btnNew.setText("New...");
btnNew.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
INewModelWizard wizard = getNewModelWizard();
IWorkbench workbench = PlatformUI.getWorkbench();
wizard.init(workbench, new StructuredSelection());
// Instantiates the wizard container with the wizard and opens it
WizardDialog dialog = new WizardDialog(workbench.getActiveWorkbenchWindow().getShell(), wizard);
dialog.create();
dialog.open();
// Updates the text widget with the newly created model
IFile createdFile = wizard.getCreatedFile();
if (createdFile != null && createdFile.exists()) {
textModelFile.setText(createdFile.getFullPath().toString());
}
}
});
}
Label lblElement = new Label(container, SWT.NONE);
lblElement.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
lblElement.setText(getTreeLabel());
treeViewer = new TreeViewer(container, SWT.BORDER);
Tree tree = treeViewer.getTree();
if (sourcePage == true) {
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
} else {
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
}
treeViewer.setContentProvider(getTreeContentProvider());
treeViewer.setLabelProvider(getTreeLabelProvider());
ViewerFilter filter = getTreeViewerFilter();
if (filter != null) {
treeViewer.addFilter(filter);
}
// Check if the initial input can be used as a valid filename
if (initialModelFilename != null) {
textModelFile.setText(initialModelFilename);
initTreeViewer(initialModelFilename);
handleTreeElementSelection(treeViewer.getSelection());
}
textModelFile.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
selectedElementURI = null;
initTreeViewer(textModelFile.getText());
getWizard().getContainer().updateButtons();
}
});
btnBrowse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
List<ViewerFilter> viewerFilters = new ArrayList<ViewerFilter>();
viewerFilters.add(new FileExtensionsViewerFilter(getFileExtensions()));
IFile[] selectedFiles = WorkspaceResourceDialog.openFileSelection(getShell(), "Select file", getFileSelectionMessage(), false, new Object[] { textModelFile.getText() }, viewerFilters);
if (selectedFiles.length > 0) {
textModelFile.setText(selectedFiles[0].getFullPath().toString());
}
}
});
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (!event.getSelection().isEmpty()) {
handleTreeElementSelection(event.getSelection());
}
getWizard().getContainer().updateButtons();
}
});
}
Aggregations