Skip to content
Permalink
Browse files

Merge pull request #6251 from dbeaver/6204_PG_Tablespaces

#6204 PG Tablespace manager
  • Loading branch information...
serge-rider committed Jul 10, 2019
2 parents 382dfc3 + 1eb057d commit cfde8a6dd9fcaf77056daac61ecab9186521cd4f
@@ -76,6 +76,7 @@
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreForeignDataWrapper"/>
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema"/>
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreDataType"/>
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace"/>
</editor>
<editor id="postgresql.source.ddl" class="org.jkiss.dbeaver.ext.postgresql.ui.editors.PostgreSourceViewEditor"
label="%db.editor.ddl.name" description="%db.editor.ddl.description" icon="#sql_text" position="additions_middle"
@@ -117,6 +118,10 @@
<configurator class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreExtensionConfigurator">
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension"/>
</configurator>
<configurator class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreTablespaceConfigurator">
<objectType name="org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace"/>
</configurator>


</extension>

@@ -178,6 +178,14 @@
public static String postgre_foreign_key_manager_checkbox_deferred;
public static String postgre_foreign_key_manager_header_edit_foreign_key;

/* Tablespaces */
public static String dialog_create_tablespace_title;
public static String dialog_create_tablespace_database;
public static String dialog_create_tablespace_name;
public static String dialog_create_tablespace_owner;
public static String dialog_create_tablespace_loc;
public static String dialog_create_tablespace_options;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, PostgreMessages.class);
@@ -145,6 +145,14 @@ dialog_create_role_label_role_name = Name
dialog_create_role_label_user_password = Password
dialog_create_role_label_user_role = Is user

# PostgreCreateTablespaceDialog
dialog_create_tablespace_title= Create tablespace
dialog_create_tablespace_database= Database
dialog_create_tablespace_name= Name
dialog_create_tablespace_owner= Owner
dialog_create_tablespace_loc= Location
dialog_create_tablespace_options= Options

# Permissions
edit_command_grant_privilege_action_grant_privilege = Grant
edit_command_grant_privilege_action_revoke_privilege = Revoke
@@ -34,6 +34,12 @@ dialog_create_extension_column_name=\u0418\u043C\u044F
dialog_create_extension_column_version=\u0412\u0435\u0440\u0441\u0438\u044F
dialog_create_extension_column_description=\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435
dialog_create_extension_database=\u0411\u0430\u0437\u0430 \u0434\u0430\u043D\u043D\u044B\u0445
dialog_create_tablespace_title= \u0421\u043E\u0437\u0434\u0430\u0442\u044C \u0442\u0430\u0431\u043B\u0438\u0447\u043D\u043E\u0435 \u043F\u0440\u043E\u0441\u0442\u0440\u0430\u043D\u0441\u0442\u0432\u043E
dialog_create_tablespace_database= \u0411\u0430\u0437\u0430 \u0434\u0430\u043D\u043D\u044B\u0445
dialog_create_tablespace_name= \u0418\u043C\u044F
dialog_create_tablespace_owner= \u0412\u043B\u0430\u0434\u0435\u043B\u0435\u0446
dialog_create_tablespace_loc= \u0420\u0430\u0441\u043F\u043E\u043B\u043E\u0436\u0435\u043D\u0438\u0435
dialog_create_tablespace_options= \u041E\u043F\u0446\u0438\u0438
dialog_setting_connection_database = \u0411\u0430\u0437\u0430 \u0434\u0430\u043D\u043D\u044B\u0445
dialog_setting_connection_host = \u0425\u043E\u0441\u0442
dialog_setting_connection_localClient = \u041B\u043E\u043A\u0430\u043B\u044C\u043D\u044B\u0439 \u043A\u043B\u0438\u0435\u043D\u0442
@@ -0,0 +1,50 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
* Copyright (C) 2019 Andrew Khitrin (ahitrin@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jkiss.dbeaver.ext.postgresql.edit;


import org.eclipse.jface.dialogs.IDialogConstants;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace;
import org.jkiss.dbeaver.ext.postgresql.ui.PostgreCreateTablespaceDialog;
import org.jkiss.dbeaver.model.edit.DBEObjectConfigurator;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.UITask;
import org.jkiss.dbeaver.ui.UIUtils;


public class PostgreTablespaceConfigurator implements DBEObjectConfigurator<PostgreTablespace> {

@Override
public PostgreTablespace configureObject(DBRProgressMonitor monitor, Object container, PostgreTablespace tablespace) {
return new UITask<PostgreTablespace>() {
@Override
protected PostgreTablespace runTask() {
PostgreCreateTablespaceDialog dialog = new PostgreCreateTablespaceDialog(UIUtils.getActiveWorkbenchShell(), tablespace);
if (dialog.open() != IDialogConstants.OK_ID) {
return null;
}
tablespace.setName(dialog.getName());
tablespace.setLoc(dialog.getLoc());
tablespace.setOwnerId(dialog.getOwner().getObjectId());
return tablespace;
}
}.execute();
}

}
@@ -0,0 +1,182 @@
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.postgresql.ui;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.postgresql.PostgreMessages;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreRole;
import org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace;
import org.jkiss.dbeaver.model.runtime.AbstractJob;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.BaseDialog;
import org.jkiss.dbeaver.utils.GeneralUtils;

import java.util.ArrayList;
import java.util.List;

/**
* PostgreCreateExtensionDialog
*/
public class PostgreCreateTablespaceDialog extends BaseDialog
{
private static final String DIALOG_ID = "DBeaver.PostgreCreateTablespaceDialog";//$NON-NLS-1$

private final PostgreTablespace newtablespace;
private List<PostgreRole> allUsers;
private PostgreRole owner;
private String name = null;
private String loc = null;
private String options = null;

public PostgreCreateTablespaceDialog(Shell parentShell, PostgreTablespace tablespace) {
super(parentShell, PostgreMessages.dialog_create_tablespace_title, null);
this.newtablespace = tablespace;
}

protected IDialogSettings getDialogBoundsSettings()
{
return UIUtils.getDialogSettings(DIALOG_ID);
}

private void checkEnabled() {
getButton(IDialogConstants.OK_ID).setEnabled(name != null && !name.isEmpty() && loc != null && !loc.isEmpty());
}

@Override
protected Composite createDialogArea(Composite parent) {
final Composite composite = super.createDialogArea(parent);

final Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(2, false));
GridData gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 600;
gd.heightHint = 200;
gd.verticalIndent = 0;
gd.horizontalIndent = 0;
group.setLayoutData(gd);

UIUtils.createLabelText(group,PostgreMessages.dialog_create_tablespace_database, newtablespace.getDatabase().getName(), SWT.BORDER | SWT.READ_ONLY); //$NON-NLS-2$

final Text nameText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_tablespace_name, ""); //$NON-NLS-2$
nameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
name = nameText.getText();
checkEnabled();
}
});

final Combo userCombo = UIUtils.createLabelCombo(group, PostgreMessages.dialog_create_tablespace_owner, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);

userCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
owner = allUsers.get(userCombo.getSelectionIndex());
checkEnabled();
}
});

final Text locText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_tablespace_loc, ""); //$NON-NLS-2$
locText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
loc = locText.getText();
checkEnabled();
}
});

final Text optionsText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_tablespace_options, ""); //$NON-NLS-2$
optionsText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
options = optionsText.getText();
}
});


new AbstractJob("Load users") {

@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<String> userNames = new ArrayList<>();
allUsers = new ArrayList<>(newtablespace.getDatabase().getUsers(monitor));
final PostgreRole dba = newtablespace.getDatabase().getDBA(monitor);
final String defUserName = dba == null ? "" : dba.getName(); //$NON-NLS-1$

UIUtils.syncExec(() -> {
for (PostgreRole authId : allUsers) {
String name = authId.getName();
userCombo.add(name);
if (name.equals(defUserName)) {
owner = authId;
}
}
userCombo.setText(defUserName);
});
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();

return composite;
}

@Override
protected void createButtonsForButtonBar(Composite parent)
{
super.createButtonsForButtonBar(parent);
getButton(IDialogConstants.OK_ID).setEnabled(false);
}

public PostgreRole getOwner() {
return owner;
}

public String getName() {
return name;
}

public String getLoc() {
return loc;
}

protected String getOptions() {
return options;
}



}
@@ -10,7 +10,8 @@ Require-Bundle: org.jkiss.dbeaver.model,
org.jkiss.dbeaver.data.gis;visibility:=reexport,
org.jkiss.bundle.gis;visibility:=reexport,
net.sf.opencsv;visibility:=reexport,
com.google.gson
com.google.gson,
org.eclipse.jface
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: %Bundle-Vendor
@@ -443,6 +443,8 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.options.name=Optio
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.options.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.owner.name=Owner
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.owner.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.loc.name=Location
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.loc.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger.name.name=Name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger.description.name=Description
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger.enabledState.name=Enabled
@@ -162,6 +162,8 @@ meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.defaultEncoding.name
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.defaultEncoding.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.defaultTablespace.name=\u0422\u0430\u0431\u043B\u0438\u0447\u043D\u043E\u0435 \u043F\u0440\u043E\u0441\u0442\u0440\u0430\u043D\u0441\u0442\u0432\u043E
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.defaultTablespace.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.loc.name=\u0420\u0430\u0441\u043F\u043E\u043B\u043E\u0436\u0435\u043D\u0438\u0435
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace.loc.description=
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.description.name=\u041A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0439
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.description.description=\u041A\u043E\u043C\u043C\u0435\u043D\u0442\u0430\u0440\u0438\u0439
meta.org.jkiss.dbeaver.ext.postgresql.model.PostgreDatabase.name.name=\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435
@@ -444,7 +444,8 @@
<manager class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreTriggerManager" objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreTrigger"/>
<manager class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreProcedureManager" objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreProcedure"/>
<manager class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreRoleManager" objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreRole"/>
<manager class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreExtensionManager" objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension"/>
<manager class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreExtensionManager" objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreExtension"/>
<manager class="org.jkiss.dbeaver.ext.postgresql.edit.PostgreTablespaceManager" objectType="org.jkiss.dbeaver.ext.postgresql.model.PostgreTablespace"/>
</extension>

<extension point="org.jkiss.dbeaver.dataTypeProvider">

0 comments on commit cfde8a6

Please sign in to comment.
You can’t perform that action at this time.