Search in sources :

Example 1 with ImageExportProviderInfo

use of com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo in project archi by archimatetool.

the class ExportAsImagePage method createFormatComboViewer.

/**
 * Create tghe Format Combo Viewer
 */
private ComboViewer createFormatComboViewer(Composite parent) {
    ComboViewer viewer = new ComboViewer(new Combo(parent, SWT.READ_ONLY | SWT.BORDER));
    viewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public void dispose() {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return fImageProviders.toArray();
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((ImageExportProviderInfo) element).getLabel();
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ImageExportProviderInfo provider = (ImageExportProviderInfo) ((IStructuredSelection) event.getSelection()).getFirstElement();
            providerChanged(provider);
        }
    });
    // $NON-NLS-1$
    viewer.setInput("");
    return viewer;
}
Also used : ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with ImageExportProviderInfo

use of com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo in project archi by archimatetool.

the class ExportAsImagePage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    setControl(container);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
    Group exportGroup = new Group(container, SWT.NULL);
    exportGroup.setText(Messages.ExportAsImagePage_2);
    exportGroup.setLayout(new GridLayout(3, false));
    exportGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    Label label = new Label(exportGroup, SWT.NULL);
    label.setText(Messages.ExportAsImagePage_3);
    fFileTextField = new Text(exportGroup, SWT.BORDER | SWT.SINGLE);
    fFileTextField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // Get last file name used
    String lastFileName = Preferences.STORE.getString(PREFS_LAST_FILE);
    if (StringUtils.isSet(lastFileName)) {
        // If we have a given name use that
        if (fName != null) {
            File file = new File(lastFileName);
            File path = file.getParentFile();
            if (path != null) {
                lastFileName = new File(path, fName).getPath();
            }
        }
        fFileTextField.setText(lastFileName);
    } else {
        // $NON-NLS-1$
        String name = (fName == null) ? "exported" : fName;
        // $NON-NLS-1$
        fFileTextField.setText(new File(System.getProperty("user.home"), name).getPath());
    }
    // Single text control so strip CRLFs
    UIUtils.conformSingleTextControl(fFileTextField);
    fFileTextField.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            validateFields();
        }
    });
    Button fileButton = new Button(exportGroup, SWT.PUSH);
    fileButton.setText(Messages.ExportAsImagePage_4);
    fileButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            File file = chooseFile();
            if (file != null) {
                fFileTextField.setText(file.getPath());
            }
        }
    });
    label = new Label(exportGroup, SWT.NULL);
    label.setText(Messages.ExportAsImagePage_5);
    fComboFormatViewer = createFormatComboViewer(exportGroup);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fComboFormatViewer.getControl().setLayoutData(gd);
    fSettingsGroup = new Group(container, SWT.NULL);
    fSettingsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    fSettingsGroup.setLayout(new GridLayout());
    fSettingsGroup.setText(Messages.ExportAsImagePage_6);
    // Validate our fields before the provider does
    validateFields();
    // Now set the combo and set to last user selected
    if (!fImageProviders.isEmpty()) {
        String selectedProviderID = Preferences.STORE.getString(PREFS_LAST_PROVIDER);
        ImageExportProviderInfo provider = getImageProviderInfoFromID(selectedProviderID);
        if (provider == null) {
            provider = fImageProviders.get(0);
        }
        fComboFormatViewer.setSelection(new StructuredSelection(provider));
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) File(java.io.File)

Example 3 with ImageExportProviderInfo

use of com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo in project archi by archimatetool.

the class ImageExportProviderManagerTests method testImageExportProviderInfo.

@Test
public void testImageExportProviderInfo() {
    IImageExportProvider provider = mock(IImageExportProvider.class);
    String id = "id1";
    String label = "My Image Exporter";
    // Can parse spaces in extensions
    ImageExportProviderInfo info = new ImageExportProviderInfo(provider, id, label, "png");
    assertEquals(provider, info.getProvider());
    assertEquals(id, info.getID());
    assertEquals(label, info.getLabel());
    assertEquals(1, info.getExtensions().size());
    assertEquals("png", info.getExtensions().get(0));
    // Can parse trailing comma
    info = new ImageExportProviderInfo(provider, id, label, "png,");
    assertEquals(1, info.getExtensions().size());
    assertEquals("png", info.getExtensions().get(0));
    // Can parse spaces in extensions
    info = new ImageExportProviderInfo(provider, id, label, "  png, svg  ");
    assertEquals(2, info.getExtensions().size());
    assertEquals("png", info.getExtensions().get(0));
    assertEquals("svg", info.getExtensions().get(1));
}
Also used : ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) Test(org.junit.Test)

Example 4 with ImageExportProviderInfo

use of com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo in project archi by archimatetool.

the class ExportAsImageWizard method performFinish.

@Override
public boolean performFinish() {
    final ImageExportProviderInfo provider = fPage.getSelectedProvider();
    if (provider == null) {
        return false;
    }
    final File file = new File(fPage.getFileName());
    // Check valid file name
    try {
        file.getCanonicalPath();
    } catch (IOException ex) {
        MessageDialog.openError(getShell(), Messages.ExportAsImageWizard_1, Messages.ExportAsImageWizard_2);
        return false;
    }
    // Make sure the file does not already exist
    if (file.exists()) {
        boolean result = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), Messages.ExportAsImageWizard_3, NLS.bind(Messages.ExportAsImageWizard_4, file));
        if (!result) {
            return false;
        }
    }
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        @Override
        public void run() {
            try {
                provider.getProvider().export(provider.getID(), file);
                fPage.storePreferences();
            } catch (Throwable ex) {
                ex.printStackTrace();
                MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.ExportAsImageWizard_5, // $NON-NLS-1$
                Messages.ExportAsImageWizard_6 + " " + ex.getMessage());
            }
        }
    });
    return true;
}
Also used : ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) IOException(java.io.IOException) File(java.io.File)

Example 5 with ImageExportProviderInfo

use of com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo in project archi by archimatetool.

the class ImageExportProviderManagerTests method testGetImageExportProviders.

@Test
public void testGetImageExportProviders() {
    List<ImageExportProviderInfo> providers = ImageExportProviderManager.getImageExportProviders();
    assertNotNull(providers);
    for (ImageExportProviderInfo info : providers) {
        assertNotNull(info.getProvider());
        assertNotNull(info.getLabel());
        assertNotNull(info.getID());
        assertNotNull(info.getExtensions());
    }
}
Also used : ImageExportProviderInfo(com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo) Test(org.junit.Test)

Aggregations

ImageExportProviderInfo (com.archimatetool.editor.diagram.ImageExportProviderManager.ImageExportProviderInfo)5 File (java.io.File)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Viewer (org.eclipse.jface.viewers.Viewer)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 Combo (org.eclipse.swt.widgets.Combo)1