Search in sources :

Example 1 with DependencyRow

use of org.obeonetwork.tools.projectlibrary.ui.wizard.imp.ImportLibraryIntoProjectWizardModel.DependencyRow in project InformationSystem by ObeoNetwork.

the class ImportLibraryIntoProjectFileSelectionPage method computeDependenciesTable.

private void computeDependenciesTable() {
    List<DependencyRow> rows = new ArrayList<>();
    for (MManifest dependency : wizard.getModel().getDependencies()) {
        DependencyRow row = new DependencyRow();
        row.setId(dependency.getProjectId());
        row.setVersion(dependency.getVersion());
        String existingVersion = getExistingVersion(dependency.getProjectId());
        if (existingVersion != null) {
            row.setExistingVersion(existingVersion);
        }
        rows.add(row);
    }
    wizard.getModel().setExistingDependenciesRows(rows);
}
Also used : DependencyRow(org.obeonetwork.tools.projectlibrary.ui.wizard.imp.ImportLibraryIntoProjectWizardModel.DependencyRow) MManifest(org.obeonetwork.dsl.manifest.MManifest) ArrayList(java.util.ArrayList)

Example 2 with DependencyRow

use of org.obeonetwork.tools.projectlibrary.ui.wizard.imp.ImportLibraryIntoProjectWizardModel.DependencyRow in project InformationSystem by ObeoNetwork.

the class ImportLibraryIntoProjectFileSelectionPage method createControl.

/**
 * Create contents of the wizard.
 * @param parent
 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(3, false));
    Label lblModelingProject = new Label(container, SWT.NONE);
    lblModelingProject.setText("Modeling project");
    comboViewer = new ComboViewer(container, SWT.NONE);
    comboViewer.setUseHashlookup(true);
    Combo combo = comboViewer.getCombo();
    combo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            computeDependenciesTable();
        }
    });
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setFont(SWTResourceManager.getFont("Segoe UI", 9, SWT.BOLD));
    lblNewLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    lblNewLabel.setText("MAR File");
    Label lblFileToImport = new Label(container, SWT.NONE);
    lblFileToImport.setText("Import file");
    txtMarFile = new Text(container, SWT.BORDER);
    txtMarFile.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    Button btnBrowse = new Button(container, SWT.NONE);
    btnBrowse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(getShell());
            dlg.setFileName(txtMarFile.getText());
            dlg.setOverwrite(true);
            dlg.setFilterExtensions(new String[] { "*.mar", "*.*" });
            dlg.setFilterNames(new String[] { "MAR files (*.mar)", "All files (*.*)" });
            String importFile = dlg.open();
            if (importFile != null) {
                try {
                    Manifest manifest = manifestServices.getManifestFromArchive(new File(importFile));
                    extractInfoFromManifest(manifest);
                } catch (FileNotFoundException e1) {
                    // TODO Error thrown
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Error thrown
                    e1.printStackTrace();
                }
                txtMarFile.setText(importFile);
                setPageComplete(isInfoComplete());
            }
        }
    });
    btnBrowse.setText("Browse...");
    Label lblProjectId = new Label(container, SWT.NONE);
    lblProjectId.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblProjectId.setText("Project ID");
    txtProjectId = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    txtProjectId.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
    Label lblVersion = new Label(container, SWT.NONE);
    lblVersion.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblVersion.setText("Version");
    txtVersion = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    txtVersion.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    Label lblCreationDate = new Label(container, SWT.NONE);
    lblCreationDate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblCreationDate.setText("Creation date");
    txtCreationDate = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    txtCreationDate.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    Label lblComment = new Label(container, SWT.NONE);
    lblComment.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
    lblComment.setText("Comment");
    txtComment = new Text(container, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI);
    txtComment.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Label lblDependencies = new Label(container, SWT.NONE);
    lblDependencies.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    lblDependencies.setText("Dependencies");
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    TableColumnLayout tcl_composite = new TableColumnLayout();
    composite.setLayout(tcl_composite);
    TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableViewerColumn tableViewerColumnId = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnProjectId = tableViewerColumnId.getColumn();
    tcl_composite.setColumnData(tblclmnProjectId, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
    tblclmnProjectId.setText("Project ID");
    tableViewerColumnId.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DependencyRow) {
                return ((DependencyRow) element).getId();
            }
            return super.getText(element);
        }
    });
    TableViewerColumn tableViewerColumnVersion = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnVersion = tableViewerColumnVersion.getColumn();
    tcl_composite.setColumnData(tblclmnVersion, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
    tblclmnVersion.setText("Version");
    tableViewerColumnVersion.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DependencyRow) {
                return ((DependencyRow) element).getVersion();
            }
            return super.getText(element);
        }
    });
    TableViewerColumn tableViewerColumnExistingVersion = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnExistingVersion = tableViewerColumnExistingVersion.getColumn();
    tcl_composite.setColumnData(tblclmnExistingVersion, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
    tblclmnExistingVersion.setText("Existing version");
    tableViewerColumnExistingVersion.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof DependencyRow) {
                return ((DependencyRow) element).getExistingVersion();
            }
            return super.getText(element);
        }
    });
    TableViewerColumn tableViewerColumnValid = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnValid = tableViewerColumnValid.getColumn();
    tcl_composite.setColumnData(tblclmnValid, new ColumnWeightData(1, ColumnWeightData.MINIMUM_WIDTH, true));
    tblclmnValid.setText("Valid");
    tableViewerColumnValid.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            // No text, we only want to display an image
            return null;
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof DependencyRow) {
                DependencyRow row = (DependencyRow) element;
                if (ManifestUtils.isGreaterOrEqual(row.getVersion(), row.getExistingVersion())) {
                    return ResourceManager.getPluginImage("org.obeonetwork.tools.projectlibrary.ui", "icons/valid.gif");
                } else {
                    return ResourceManager.getPluginImage("org.obeonetwork.tools.projectlibrary.ui", "icons/invalid.gif");
                }
            }
            return super.getImage(element);
        }
    });
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    tableViewer.setContentProvider(new ArrayContentProvider());
    setPageComplete(isInfoComplete());
    m_bindingContext = initDataBindings();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Label(org.eclipse.swt.widgets.Label) FileNotFoundException(java.io.FileNotFoundException) Combo(org.eclipse.swt.widgets.Combo) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DependencyRow(org.obeonetwork.tools.projectlibrary.ui.wizard.imp.ImportLibraryIntoProjectWizardModel.DependencyRow) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) MManifest(org.obeonetwork.dsl.manifest.MManifest) TableColumn(org.eclipse.swt.widgets.TableColumn) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

MManifest (org.obeonetwork.dsl.manifest.MManifest)2 DependencyRow (org.obeonetwork.tools.projectlibrary.ui.wizard.imp.ImportLibraryIntoProjectWizardModel.DependencyRow)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Manifest (java.util.jar.Manifest)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1