use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase in project dbeaver by serge-rider.
the class MySQLExportWizardPageObjects method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 1);
Group objectsGroup = UIUtils.createControlGroup(composite, MySQLMessages.tools_db_export_wizard_page_settings_group_objects, 1, GridData.FILL_HORIZONTAL, 0);
objectsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
SashForm sash = new CustomSashForm(objectsGroup, SWT.VERTICAL);
sash.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite catPanel = UIUtils.createPlaceholder(sash, 1);
catPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
catalogTable = new Table(catPanel, SWT.BORDER | SWT.CHECK);
catalogTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
TableItem item = (TableItem) event.item;
if (item != null) {
MySQLCatalog catalog = (MySQLCatalog) item.getData();
if (event.detail == SWT.CHECK) {
catalogTable.select(catalogTable.indexOf(item));
checkedObjects.remove(catalog);
}
loadTables(catalog);
updateState();
}
}
});
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 50;
catalogTable.setLayoutData(gd);
Composite buttonsPanel = UIUtils.createPlaceholder(catPanel, 3, 5);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
new Label(buttonsPanel, SWT.NONE).setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
createCheckButtons(buttonsPanel, catalogTable);
}
final Button exportViewsCheck;
{
Composite tablesPanel = UIUtils.createPlaceholder(sash, 1);
tablesPanel.setLayoutData(new GridData(GridData.FILL_BOTH));
tablesTable = new Table(tablesPanel, SWT.BORDER | SWT.CHECK);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 50;
tablesTable.setLayoutData(gd);
tablesTable.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
if (event.detail == SWT.CHECK) {
updateCheckedTables();
updateState();
}
}
});
Composite buttonsPanel = UIUtils.createPlaceholder(tablesPanel, 3, 5);
buttonsPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
exportViewsCheck = UIUtils.createCheckbox(buttonsPanel, "Show views", false);
exportViewsCheck.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
wizard.showViews = exportViewsCheck.getSelection();
loadTables(null);
}
});
exportViewsCheck.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL));
createCheckButtons(buttonsPanel, tablesTable);
}
MySQLDataSource dataSource = null;
Set<MySQLCatalog> activeCatalogs = new LinkedHashSet<>();
for (DBSObject object : wizard.getDatabaseObjects()) {
if (object instanceof MySQLCatalog) {
activeCatalogs.add((MySQLCatalog) object);
dataSource = ((MySQLCatalog) object).getDataSource();
} else if (object instanceof MySQLTableBase) {
MySQLCatalog catalog = ((MySQLTableBase) object).getContainer();
dataSource = catalog.getDataSource();
activeCatalogs.add(catalog);
Set<MySQLTableBase> tables = checkedObjects.get(catalog);
if (tables == null) {
tables = new HashSet<>();
checkedObjects.put(catalog, tables);
}
tables.add((MySQLTableBase) object);
if (((MySQLTableBase) object).isView()) {
wizard.showViews = true;
exportViewsCheck.setSelection(true);
}
} else if (object.getDataSource() instanceof MySQLDataSource) {
dataSource = (MySQLDataSource) object.getDataSource();
}
}
if (dataSource != null) {
boolean tablesLoaded = false;
for (MySQLCatalog catalog : dataSource.getCatalogs()) {
TableItem item = new TableItem(catalogTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(DBIcon.TREE_DATABASE));
item.setText(0, catalog.getName());
item.setData(catalog);
if (activeCatalogs.contains(catalog)) {
item.setChecked(true);
catalogTable.select(catalogTable.indexOf(item));
if (!tablesLoaded) {
loadTables(catalog);
tablesLoaded = true;
}
}
}
}
updateState();
setControl(composite);
}
use of org.jkiss.dbeaver.ext.mysql.model.MySQLTableBase in project dbeaver by serge-rider.
the class MySQLExportWizardPageObjects method loadTables.
private void loadTables(final MySQLCatalog catalog) {
if (catalog != null) {
curCatalog = catalog;
}
if (curCatalog == null) {
return;
}
final boolean isCatalogChecked = isChecked(curCatalog);
final Set<MySQLTableBase> checkedObjects = this.checkedObjects.get(curCatalog);
new AbstractJob("Load '" + curCatalog.getName() + "' tables") {
{
setUser(true);
}
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<MySQLTableBase> objects = new ArrayList<>();
objects.addAll(curCatalog.getTables(monitor));
if (wizard.showViews) {
objects.addAll(curCatalog.getViews(monitor));
}
Collections.sort(objects, DBUtils.nameComparator());
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
tablesTable.removeAll();
for (MySQLTableBase table : objects) {
TableItem item = new TableItem(tablesTable, SWT.NONE);
item.setImage(DBeaverIcons.getImage(table.isView() ? DBIcon.TREE_VIEW : DBIcon.TREE_TABLE));
item.setText(0, table.getName());
item.setData(table);
item.setChecked(isCatalogChecked && (checkedObjects == null || checkedObjects.contains(table)));
}
}
});
} catch (DBException e) {
UIUtils.showErrorDialog(null, "Table list", "Can't read table list", e);
}
return Status.OK_STATUS;
}
}.schedule();
}
Aggregations