use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class NavigatorHandlerCopyAbstract method copySelection.
private void copySelection(IWorkbenchWindow workbenchWindow, IWorkbenchPart activePart, ISelection selection) {
ClipboardData clipboardData = new ClipboardData();
{
IClipboardSource clipboardSource = activePart.getAdapter(IClipboardSource.class);
if (clipboardSource != null) {
clipboardSource.addClipboardData(getCopyMode(), clipboardData);
}
}
if (selection instanceof IStructuredSelection && !selection.isEmpty()) {
final IStructuredSelection structSelection = (IStructuredSelection) selection;
List<DBNNode> selectedNodes = new ArrayList<>();
List<DBPNamedObject> selectedObjects = new ArrayList<>();
List<String> selectedFiles = new ArrayList<>();
StringBuilder buf = new StringBuilder();
for (Iterator<?> iter = structSelection.iterator(); iter.hasNext(); ) {
Object object = iter.next();
String objectValue = getObjectDisplayString(object);
if (objectValue == null) {
continue;
}
DBNNode node = RuntimeUtils.getObjectAdapter(object, DBNNode.class);
DBPNamedObject dbObject = null;
if (node instanceof DBNDatabaseNode) {
dbObject = ((DBNDatabaseNode) node).getObject();
}
if (dbObject == null) {
dbObject = RuntimeUtils.getObjectAdapter(object, DBPNamedObject.class);
}
if (node != null) {
selectedNodes.add(node);
}
if (node instanceof DBNResource && ((DBNResource) node).getResource() instanceof IFile) {
final IFile file = (IFile) ((DBNResource) node).getResource();
if (file != null) {
selectedFiles.add(file.getLocation().makeAbsolute().toFile().getAbsolutePath());
}
}
if (dbObject != null) {
selectedObjects.add(dbObject);
}
if (buf.length() > 0) {
buf.append(GeneralUtils.getDefaultLineSeparator());
}
buf.append(objectValue);
}
{
if (buf.length() > 0 && !clipboardData.hasTransfer(TextTransfer.getInstance())) {
clipboardData.addTransfer(TextTransfer.getInstance(), buf.toString());
}
if (!selectedNodes.isEmpty() && !clipboardData.hasTransfer(TreeNodeTransfer.getInstance())) {
clipboardData.addTransfer(TreeNodeTransfer.getInstance(), selectedNodes);
}
if (!selectedObjects.isEmpty() && !clipboardData.hasTransfer(DatabaseObjectTransfer.getInstance())) {
clipboardData.addTransfer(DatabaseObjectTransfer.getInstance(), selectedObjects);
}
if (!selectedFiles.isEmpty() && !clipboardData.hasTransfer(FileTransfer.getInstance())) {
clipboardData.addTransfer(FileTransfer.getInstance(), selectedFiles.toArray(new String[selectedFiles.size()]));
}
}
}
if (clipboardData.hasData()) {
clipboardData.pushToClipboard(workbenchWindow.getShell().getDisplay());
ObjectPropertyTester.firePropertyChange(ObjectPropertyTester.PROP_CAN_PASTE);
}
}
use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class DataExporterSQL method exportHeader.
@Override
public void exportHeader(DBCSession session) throws DBException, IOException {
columns = getSite().getAttributes();
DBPNamedObject source = getSite().getSource();
if (source instanceof DBSObject) {
tableName = omitSchema ? DBUtils.getQuotedIdentifier((DBSObject) source) : DBUtils.getObjectFullName(source, DBPEvaluationContext.UI);
} else {
throw new DBException("SQL export may be done only from table object");
}
rowCount = 0;
}
use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class DiagramObjectCollector method generateEntityList.
public static List<ERDEntity> generateEntityList(final EntityDiagram diagram, Collection<DBPNamedObject> objects) {
final List<DBSObject> roots = new ArrayList<>();
for (DBPNamedObject object : objects) {
if (object instanceof DBSObject) {
roots.add((DBSObject) object);
}
}
final List<ERDEntity> entities = new ArrayList<>();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DiagramObjectCollector collector = new DiagramObjectCollector(diagram);
try {
collector.generateDiagramObjects(monitor, roots);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
entities.addAll(collector.getDiagramEntities());
}
});
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
} catch (InterruptedException e) {
// interrupted
}
return entities;
}
use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class NodeDropTargetListener method createTargetRequest.
@Override
protected Request createTargetRequest() {
CreateRequest request = new CreateRequest();
request.setFactory(new CreationFactory() {
@Override
public Object getNewObject() {
Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
if (objects == null) {
return null;
}
return DiagramObjectCollector.generateEntityList(((DiagramPart) getViewer().getRootEditPart().getContents()).getDiagram(), objects);
}
@Override
public Object getObjectType() {
return RequestConstants.REQ_CREATE;
}
});
request.setLocation(getDropLocation());
return request;
}
use of org.jkiss.dbeaver.model.DBPNamedObject in project dbeaver by serge-rider.
the class ERDHandlerPaste method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Control control = (Control) HandlerUtil.getVariable(event, ISources.ACTIVE_FOCUS_CONTROL_NAME);
if (control != null) {
ERDEditorPart editor = ERDEditorAdapter.getEditor(control);
if (editor != null && !editor.isReadOnly()) {
final Collection<DBPNamedObject> objects = DatabaseObjectTransfer.getInstance().getObject();
if (!CommonUtils.isEmpty(objects)) {
final List<ERDEntity> erdEntities = DiagramObjectCollector.generateEntityList(editor.getDiagram(), objects);
if (!CommonUtils.isEmpty(erdEntities)) {
EntityAddCommand command = new EntityAddCommand(editor.getDiagramPart(), erdEntities, new Point(10, 10));
editor.getCommandStack().execute(command);
}
}
}
}
return null;
}
Aggregations