Search in sources :

Example 6 with IModelProject

use of org.eclipse.vorto.core.ui.model.IModelProject in project vorto by eclipse.

the class AbstractProjectSelectionViewPart method createPartControl.

/**
 * Create contents of the view part.
 *
 * @param parent
 */
@Override
public void createPartControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    FormLayout layout = new FormLayout();
    layout.marginHeight = 5;
    layout.marginWidth = 5;
    container.setLayout(layout);
    projectSelectionViewer = createProjectSelectionViewer(container, getViewerText());
    projectSelectionViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IModelProject) {
                IModelProject project = (IModelProject) element;
                return project.getProject().getName();
            }
            return super.getText(element);
        }
    });
    projectSelectionViewer.setContentProvider(ArrayContentProvider.getInstance());
    Collection<IModelProject> modelProjects = getModelProjects();
    projectSelectionViewer.setInput(modelProjects);
    projectSelectionViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection iSelection = (IStructuredSelection) event.getSelection();
                IModelProject project = (IModelProject) iSelection.getFirstElement();
                selectedProject = project;
                populate(selectedProject);
            }
        }
    });
    hookListeners();
    Composite modelPanel = createViewerComposite(container, projectSelectionViewer.getCombo());
    datatypeTreeViewer = getDataTypeTreeViewer(modelPanel);
    functionBlockTreeViewer = getFunctionblockTreeViewer(modelPanel);
    infoModelTreeViewer = getInfomodelTreeViewer(modelPanel);
    multipleSelectionProvider = new MultipleSelectionProvider();
    getSite().setSelectionProvider(multipleSelectionProvider);
    if (!modelProjects.isEmpty()) {
        setSelectedProject(modelProjects.iterator().next());
    }
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) Composite(org.eclipse.swt.widgets.Composite) IModelProject(org.eclipse.vorto.core.ui.model.IModelProject) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 7 with IModelProject

use of org.eclipse.vorto.core.ui.model.IModelProject in project vorto by eclipse.

the class AbstractProjectSelectionViewPart method createProjectSelectionViewer.

private ComboViewer createProjectSelectionViewer(final Composite container, String labelStr) {
    Button newProjectButton = new Button(container, SWT.NONE);
    newProjectButton.setImage(ImageUtil.getImage("add_obj.gif"));
    newProjectButton.setToolTipText(getAddToolTipText());
    newProjectButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            switch(e.type) {
                case SWT.Selection:
                    WizardDialog wizardDialog = new WizardDialog(container.getShell(), getProjectWizard());
                    if (wizardDialog.open() == Window.OK) {
                        projectSelectionViewer.setInput(getModelProjects());
                        AbstractProjectWizardPage page = (AbstractProjectWizardPage) wizardDialog.getCurrentPage();
                        IModelProject project = getModelProjectFromName(page.getProjName());
                        selectedProject = project;
                        projectSelectionViewer.setSelection(new StructuredSelection(project), true);
                    }
                    break;
                default:
            }
        }
    });
    FormData buttonFormdata = new FormData();
    buttonFormdata.top = new FormAttachment(0, 0);
    buttonFormdata.right = new FormAttachment(100, 0);
    newProjectButton.setLayoutData(buttonFormdata);
    Button deleteButton = new Button(container, SWT.NONE);
    deleteButton.setImage(ImageUtil.getImage("delete.gif"));
    deleteButton.setToolTipText(getDeleteToolTipText());
    deleteButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event e) {
            switch(e.type) {
                case SWT.Selection:
                    if (selectedProject != null) {
                        if (!Display.getDefault().isDisposed()) {
                            Display.getDefault().syncExec(newDeleteProjectRunnable(selectedProject));
                        }
                    }
                    break;
                default:
            }
        }
    });
    FormData deleteButtonFormdata = new FormData();
    deleteButtonFormdata.top = new FormAttachment(0, 0);
    deleteButtonFormdata.right = new FormAttachment(newProjectButton, -10);
    deleteButton.setLayoutData(deleteButtonFormdata);
    ComboViewer comboViewer = new ComboViewer(container, SWT.READ_ONLY);
    Combo combo = comboViewer.getCombo();
    FormData viewerFormData = new FormData();
    viewerFormData.top = new FormAttachment(newProjectButton, 10);
    viewerFormData.left = new FormAttachment(0, 0);
    viewerFormData.right = new FormAttachment(100, 0);
    combo.setLayoutData(viewerFormData);
    Label label = new Label(container, SWT.NONE);
    label.setText(labelStr);
    FormData labelFormData = new FormData();
    labelFormData.bottom = new FormAttachment(comboViewer.getCombo(), -10);
    labelFormData.left = new FormAttachment(0, 0);
    label.setLayoutData(labelFormData);
    return comboViewer;
}
Also used : FormData(org.eclipse.swt.layout.FormData) RemoveModelListener(org.eclipse.vorto.perspective.listener.RemoveModelListener) ErrorDiagnosticListener(org.eclipse.vorto.perspective.listener.ErrorDiagnosticListener) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) RemoveModelProjectListener(org.eclipse.vorto.perspective.listener.RemoveModelProjectListener) Listener(org.eclipse.swt.widgets.Listener) RemoveImportListener(org.eclipse.vorto.perspective.listener.RemoveImportListener) AbstractProjectWizardPage(org.eclipse.vorto.wizard.AbstractProjectWizardPage) Button(org.eclipse.swt.widgets.Button) IModelProject(org.eclipse.vorto.core.ui.model.IModelProject) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Label(org.eclipse.swt.widgets.Label) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) Combo(org.eclipse.swt.widgets.Combo) WizardDialog(org.eclipse.jface.wizard.WizardDialog) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Aggregations

IModelProject (org.eclipse.vorto.core.ui.model.IModelProject)7 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 IWorkspace (org.eclipse.core.resources.IWorkspace)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)3 PartInitException (org.eclipse.ui.PartInitException)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 Button (org.eclipse.swt.widgets.Button)1