Search in sources :

Example 1 with INewModelWizard

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();
        }
    });
}
Also used : IFile(org.eclipse.core.resources.IFile) FileExtensionsViewerFilter(fr.gouv.mindef.safran.database.ui.dialogs.FileExtensionsViewerFilter) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ModifyListener(org.eclipse.swt.events.ModifyListener) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) ArrayList(java.util.ArrayList) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) INewModelWizard(fr.gouv.mindef.safran.database.ui.wizards.scaffolding.newmodel.INewModelWizard) Text(org.eclipse.swt.widgets.Text) IWorkbench(org.eclipse.ui.IWorkbench) FileExtensionsViewerFilter(fr.gouv.mindef.safran.database.ui.dialogs.FileExtensionsViewerFilter) GridData(org.eclipse.swt.layout.GridData) EObject(org.eclipse.emf.ecore.EObject) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

FileExtensionsViewerFilter (fr.gouv.mindef.safran.database.ui.dialogs.FileExtensionsViewerFilter)1 INewModelWizard (fr.gouv.mindef.safran.database.ui.wizards.scaffolding.newmodel.INewModelWizard)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 EObject (org.eclipse.emf.ecore.EObject)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1