use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.
the class ExporterSettingsTab method createPropertySheet.
private Control createPropertySheet(Composite exportersComposite) {
propertySheet = new PropertySheetPage() {
public void handleEntrySelection(ISelection selection) {
super.handleEntrySelection(selection);
IStructuredSelection iss = (IStructuredSelection) selection;
IPropertyDescriptor propertyDescriptor = null;
if (!iss.isEmpty()) {
MyPropertySheetEntry mse = (MyPropertySheetEntry) iss.getFirstElement();
propertyDescriptor = mse.getMyDescriptor();
}
updateCurrentDescriptor(propertyDescriptor);
}
};
propertySheet.createControl(exportersComposite);
final PropertySheetEntry propertySheetEntry = new MyPropertySheetEntry();
propertySheetEntry.setPropertySourceProvider(new IPropertySourceProvider() {
public IPropertySource getPropertySource(Object object) {
if (object instanceof ExporterFactory) {
return new ExporterFactoryPropertySource((ExporterFactory) object) {
public void setPropertyValue(Object id, Object value) {
super.setPropertyValue(id, value);
dialogChanged();
}
};
} else {
return null;
}
}
});
propertySheet.setRootEntry(propertySheetEntry);
// propertySheetEntry.setValues( new Object[] { this });
getExporterTable().addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection s = (IStructuredSelection) event.getSelection();
if (s.isEmpty()) {
if (add != null)
add.setEnabled(false);
if (remove != null)
remove.setEnabled(false);
if (edit != null)
edit.setEnabled(false);
propertySheetEntry.setValues(new Object[0]);
} else {
if (add != null)
add.setEnabled(true);
boolean hasSelection = false;
if (currentDescriptor != null) {
hasSelection = true;
}
if (remove != null)
remove.setEnabled(hasSelection);
if (edit != null)
edit.setEnabled(hasSelection);
ExporterFactory ep = (ExporterFactory) s.getFirstElement();
propertySheetEntry.setValues(new Object[] { ep });
// if(ep.isEnabled( configuration ))
}
}
});
Control control = propertySheet.getControl();
if (control instanceof Tree && !control.isDisposed()) {
Tree tree = (Tree) control;
tree.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent e) {
}
public void widgetSelected(SelectionEvent e) {
IPropertyDescriptor propertyDescriptor = null;
if (e.item != null && e.item.getData() != null) {
MyPropertySheetEntry mse = (MyPropertySheetEntry) e.item.getData();
propertyDescriptor = mse.getMyDescriptor();
}
updateCurrentDescriptor(propertyDescriptor);
}
});
}
return control;
}
use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.
the class ExporterSettingsTab method createExporterTable.
private void createExporterTable(Composite parent) {
exporterUpDown = new UpDownListComposite(parent, SWT.NONE, HibernateConsoleMessages.ExporterSettingsTab_exporters, true, new ExporterLabelProvider(), new ExporterContentProvider()) {
protected Object[] handleAdd(int idx) {
switch(idx) {
case 0:
Object[] selectExporters = selectExporters(getShell(), HibernateConsoleMessages.ExporterSettingsTab_add_exporter, HibernateConsoleMessages.ExporterSettingsTab_select_exporter_you_want_to_add);
for (int i = 0; i < selectExporters.length; i++) {
ExporterDefinition exporterDefinition = (ExporterDefinition) selectExporters[i];
addDef(exporterDefinition);
}
// { exporterFactory };
return new Object[0];
case 1:
getExporterTable().setAllChecked(true);
selectedExporters.clear();
observableFactoryList.copyUnderlyingList(selectedExporters);
dialogChanged();
break;
case 2:
getExporterTable().setAllChecked(false);
selectedExporters.clear();
dialogChanged();
break;
default:
break;
}
return null;
}
private void addDef(ExporterDefinition expDef) {
int initialCount = getTable().getItemCount();
boolean duplicate = false;
do {
duplicate = false;
initialCount++;
for (ExporterFactory def : observableFactoryList.getList()) {
if (def.getId().equals("" + initialCount)) {
// $NON-NLS-1$
duplicate = true;
}
}
} while (duplicate);
// $NON-NLS-1$
String initialName = "" + initialCount;
ExporterFactory exporterFactory = new ExporterFactory(expDef, initialName);
observableFactoryList.add(exporterFactory);
selectedExporters.add(exporterFactory);
((CheckboxTableViewer) getTableViewer()).setChecked(exporterFactory, true);
}
@SuppressWarnings("unchecked")
protected void handleRemove() {
IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
if (selection != null) {
Iterator<Object> iterator = selection.iterator();
while (iterator.hasNext()) {
Object item = iterator.next();
observableFactoryList.remove((ExporterFactory) item);
deletedExporterIds.add(((ExporterFactory) item).getId());
}
// getTableViewer().setSelection(StructuredSelection.EMPTY);
listChanged();
}
}
protected void moveSelectionDown() {
Table table = getTableViewer().getTable();
int[] indices = table.getSelectionIndices();
if (indices.length < 1) {
return;
}
int[] newSelection = new int[indices.length];
int max = table.getItemCount() - 1;
for (int i = indices.length - 1; i >= 0; i--) {
int index = indices[i];
if (index < max) {
ExporterFactory data = (ExporterFactory) getTableViewer().getElementAt(index);
observableFactoryList.moveTo(index + 1, data);
newSelection[i] = index + 1;
}
}
table.setSelection(newSelection);
listChanged();
}
protected void moveSelectionUp() {
Table table = getTableViewer().getTable();
int[] indices = table.getSelectionIndices();
int[] newSelection = new int[indices.length];
for (int i = 0; i < indices.length; i++) {
int index = indices[i];
if (index > 0) {
ExporterFactory data = (ExporterFactory) getTableViewer().getElementAt(index);
observableFactoryList.moveTo(index - 1, data);
newSelection[i] = index - 1;
}
}
table.setSelection(newSelection);
listChanged();
}
protected String[] getAddButtonLabels() {
return new String[] { HibernateConsoleMessages.ExporterSettingsTab_add, HibernateConsoleMessages.ExporterSettingsTab_select_all, HibernateConsoleMessages.ExporterSettingsTab_deselect_all };
}
protected void listChanged() {
dialogChanged();
}
};
getExporterTable().addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent event) {
ExporterFactory factory = (ExporterFactory) event.getElement();
if (!event.getChecked() && selectedExporters.contains(factory)) {
selectedExporters.remove(factory);
} else if (event.getChecked() && !selectedExporters.contains(factory)) {
selectedExporters.add(factory);
}
dialogChanged();
}
});
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = GridData.FILL;
gd.horizontalAlignment = GridData.FILL;
exporterUpDown.setLayoutData(gd);
}
use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.
the class ExporterSettingsTab method dialogChanged.
private void dialogChanged() {
// TODO: only active if configname in
boolean configSelected = true;
if (!configSelected) {
updateStatus(HibernateConsoleMessages.ExporterSettingsTab_console_configuration_must_be_specified);
return;
}
if (selectedExporters.size() == 0) {
updateStatus(HibernateConsoleMessages.ExporterSettingsTab_at_least_one_exporter_option_must_be_selected);
return;
}
String msg = null;
// Iterator iterator = observableFactoryList.getList().iterator(); // check all exporters
for (ExporterFactory ef : selectedExporters) {
// check only selected exporters
String str = ef.getProperties().get(ExporterFactoryStrings.OUTPUTDIR);
if (str != null) {
// $NON-NLS-1$
msg = PathHelper.checkDirectory(str, HibernateConsoleMessages.ExporterSettingsTab_output_directory_for + " " + ef.getExporterDefinition().getDescription(), true);
if (msg != null) {
break;
}
}
str = ef.getProperties().get(ExporterFactoryStrings.TEMPLATE_PATH);
if (str != null) {
// $NON-NLS-1$
msg = PathHelper.checkDirectory(str, HibernateConsoleMessages.ExporterSettingsTab_template_directory_for + " " + ef.getExporterDefinition().getDescription(), true);
if (msg != null) {
break;
}
}
str = ef.getProperties().get(ExporterFactoryStrings.QUERY_STRING);
if (str != null) {
str = str.trim();
if (str.length() == 0) {
msg = NLS.bind(HibernateConsoleMessages.ExporterSettingsTab_query_should_have_not_empty_value, ef.getExporterDefinition().getDescription());
break;
}
}
}
updateStatus(msg);
}
use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.
the class ConsoleExtension method launchExporters.
public Map<String, File[]> launchExporters(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(configuration);
Assert.isNotNull(monitor);
ExporterAttributes attributes = new ExporterAttributes(configuration);
List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext(); ) {
ExporterFactory exFactory = iter.next();
if (!exFactory.isEnabled(configuration)) {
iter.remove();
}
}
try {
Set<String> outputDirectories = new HashSet<String>();
ExporterFactory[] exporters = exporterFactories.toArray(new ExporterFactory[exporterFactories.size()]);
IArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);
for (String path : outputDirectories) {
CodeGenerationUtils.refreshOutputDir(path);
}
// eclipse will format the uptodate files!
if (collector != null) {
Map<String, File[]> map = new HashMap<String, File[]>();
Set<String> types = collector.getFileTypes();
for (String type : types) {
File[] files = collector.getFiles(type.toString());
map.put(type, files);
}
return map;
}
} catch (Exception e) {
throw new CoreException(HibernatePlugin.throwableToStatus(e, 666));
} catch (NoClassDefFoundError e) {
throw new CoreException(HibernatePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror, e), 666));
} finally {
monitor.done();
}
return null;
}
use of org.hibernate.eclipse.console.model.impl.ExporterFactory in project jbosstools-hibernate by jbosstools.
the class ExporterAttributes method readExporterFactories.
private List<ExporterFactory> readExporterFactories(ILaunchConfiguration configuration) throws CoreException {
List<String> exporterNames = configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, (List<String>) null);
if (exporterNames != null) {
Map<String, ExporterDefinition> exDefinitions = ExtensionManager.findExporterDefinitionsAsMap();
List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
for (String exporterId : exporterNames) {
// $NON-NLS-1$
String extensionId = configuration.getAttribute(getLaunchAttributePrefix(exporterId) + ".extension_id", (String) null);
ExporterDefinition expDef = exDefinitions.get(extensionId);
if (expDef == null) {
String out = NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in, extensionId, configuration.getName());
throw new HibernateConsoleRuntimeException(out);
} else {
ExporterFactory exporterFactory = new ExporterFactory(expDef, exporterId);
exporterFactory.isEnabled(configuration);
factories.add(exporterFactory);
Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
new HashMap<String, String>());
exporterFactory.setProperties(props);
}
}
return factories;
} else {
// fall back to old way of reading if list of exporters does not exist.
ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
for (int i = 0; i < exDefinitions.length; i++) {
ExporterDefinition expDef = exDefinitions[i];
ExporterFactory exporterFactory = new ExporterFactory(expDef, expDef.getId());
exporterFactory.isEnabled(configuration);
factories.add(exporterFactory);
Map<String, String> props = configuration.getAttribute(getLaunchAttributePrefix(exporterFactory.getId()) + ".properties", // $NON-NLS-1$
new HashMap<String, String>());
exporterFactory.setProperties(props);
}
return factories;
}
}
Aggregations