use of fr.gouv.mindef.safran.database.ui.dialogs.FileExtensionsViewerFilter in project InformationSystem by ObeoNetwork.
the class DatabaseImportWizardPage method createControl.
/* (non-Javadoc)
* @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#createAdvancedControls(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
lblError = new Label(composite, SWT.NONE);
lblError.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
lblError.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
Label lblDbVendor = new Label(composite, SWT.NONE);
lblDbVendor.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDbVendor.setText("DB Vendor :");
comboDbVendor = new Combo(composite, SWT.NONE);
comboDbVendor.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label lblHost = new Label(composite, SWT.NONE);
lblHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblHost.setText("Host :");
txtHost = new Text(composite, SWT.BORDER);
txtHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label lblPort = new Label(composite, SWT.NONE);
lblPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblPort.setText("Port :");
txtPort = new Text(composite, SWT.BORDER);
txtPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
final Label lblDatabase = new Label(composite, SWT.NONE);
lblDatabase.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblDatabase.setText("Database :");
txtDatabase = new Text(composite, SWT.BORDER);
txtDatabase.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label lblSchema = new Label(composite, SWT.NONE);
lblSchema.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblSchema.setText("Schema :");
txtSchema = new Text(composite, SWT.BORDER);
txtSchema.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label lblUser = new Label(composite, SWT.NONE);
lblUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblUser.setText("User :");
txtUser = new Text(composite, SWT.BORDER);
txtUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label lblPassword = new Label(composite, SWT.NONE);
lblPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblPassword.setText("Password :");
txtPassword = new Text(composite, SWT.BORDER);
txtPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
Label lblUrl = new Label(composite, SWT.NONE);
lblUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblUrl.setText("URL :");
txtUrl = new Text(composite, SWT.BORDER);
txtUrl.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
comboDbVendor.setItems(DB_VENDOR_CHOICES);
comboDbVendor.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
txtSchema.setEnabled(!DB_MYSQL_5.equals(comboDbVendor.getText()));
txtHost.setEnabled(!DB_H2_13.equals(comboDbVendor.getText()));
txtPort.setEnabled(!DB_H2_13.equals(comboDbVendor.getText()));
}
});
txtSchema.setEnabled(!DB_MYSQL_5.equals(comboDbVendor.getText()));
Label lblModelFile = new Label(composite, SWT.NONE);
lblModelFile.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblModelFile.setText("New model file :");
txtModelFile = new Text(composite, SWT.BORDER);
txtModelFile.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
txtModelFile.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
setPageComplete(checkStatus());
}
});
Button btnBrowseFile = new Button(composite, SWT.NONE);
btnBrowseFile.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
btnBrowseFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Collection<ViewerFilter> filters = new ArrayList<ViewerFilter>();
filters.add(new FileExtensionsViewerFilter(new String[] { DATABASE_FILE_EXTENSION }));
IResource selectedResource = SpecificWorkspaceResourceDialog.openFileSelection(getShell(), "Output model", "Specify the file to create", new Path(txtModelFile.getText()), filters, DATABASE_FILE_EXTENSION);
if (selectedResource != null) {
txtModelFile.setText(selectedResource.getFullPath().toString());
}
}
});
btnBrowseFile.setText("Browse...");
btnBrowseFile.setSize(62, 23);
Label lblReferencedModelFiles = new Label(composite, SWT.NONE);
lblReferencedModelFiles.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
lblReferencedModelFiles.setText("Referenced files :");
final List<ViewerFilter> filters = new ArrayList<ViewerFilter>();
filters.add(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IFile) {
IResource workspaceResource = (IResource) element;
return referencedFiles.contains(workspaceResource) == false && DATABASE_FILE_EXTENSION.equals(workspaceResource.getFileExtension());
}
return true;
}
});
Button btnAddReferencedFile = new Button(composite, SWT.NONE);
btnAddReferencedFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
btnAddReferencedFile.setText("Add...");
btnAddReferencedFile.setSize(62, 23);
btnAddReferencedFile.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
IFile[] selectedFiles = WorkspaceResourceDialog.openFileSelection(getShell(), "Add referenced file", "Select the referenced files (*." + DATABASE_FILE_EXTENSION + ")", true, null, filters);
for (IFile selectedFile : selectedFiles) {
referencedFiles.add(selectedFile);
}
listReferencedModelFiles.refresh();
}
});
Button btnRemoveReferencedFile = new Button(composite, SWT.NONE);
btnRemoveReferencedFile.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
btnRemoveReferencedFile.setText("Remove");
btnRemoveReferencedFile.setSize(62, 23);
btnRemoveReferencedFile.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
StructuredSelection selectedFile = (StructuredSelection) listReferencedModelFiles.getSelection();
if (selectedFile.getFirstElement() instanceof IFile) {
referencedFiles.remove((IFile) selectedFile.getFirstElement());
listReferencedModelFiles.refresh();
}
}
});
listReferencedModelFiles = new ListViewer(composite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
listReferencedModelFiles.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
listReferencedModelFiles.setContentProvider(new ArrayContentProvider());
listReferencedModelFiles.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
IFile file = (IFile) element;
return file.getFullPath().toString();
}
});
setControl(composite);
initInput();
bindValues();
}
use of fr.gouv.mindef.safran.database.ui.dialogs.FileExtensionsViewerFilter 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