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;
}
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));
}
}
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));
}
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;
}
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());
}
}
Aggregations