Skip to content

Commit

Permalink
TEIIDDES-2821
Browse files Browse the repository at this point in the history
* add setControl() to the description tab on data role dialog
* changed behavior of dialog to create temporary data role and let the
panel's action copy over the changed properties to keep data role in
sync.
  • Loading branch information
blafond committed Apr 8, 2016
1 parent db090a1 commit f15c61e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.HashSet;
import java.util.Set;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
Expand Down Expand Up @@ -51,6 +53,8 @@
import org.teiid.designer.roles.ui.wizard.panels.CrudPanel;
import org.teiid.designer.roles.ui.wizard.panels.RowBasedSecurityPanel;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion.Version;
import org.teiid.designer.ui.common.UILabelUtil;
import org.teiid.designer.ui.common.UiLabelConstants;
import org.teiid.designer.ui.common.InternalUiConstants.Widgets;
import org.teiid.designer.ui.common.graphics.GlobalUiColorManager;
import org.teiid.designer.ui.common.text.StyledTextEditor;
Expand Down Expand Up @@ -82,7 +86,8 @@ private static String getString( final String id ) {
}

private DataRole existingDataRole;
// private DataRole dataRole;
private DataRole editedDataRole;

private Container tempContainer;

private boolean isEdit = false;
Expand Down Expand Up @@ -151,7 +156,9 @@ public DataRoleWizard(Container tempContainer, DataRole existingDataRole, Allowe
this.allowCreateTempTables = false;
this.grantAll = false;
this.mappedRoleNames = new HashSet<String>();
this.editedDataRole = new DataRole(this.dataRoleName);
} else {
this.editedDataRole = this.existingDataRole.clone();
this.dataRoleName = existingDataRole.getName();
this.description = existingDataRole.getDescription();
this.allowCreateTempTables = existingDataRole.isAllowCreateTempTables();
Expand Down Expand Up @@ -248,15 +255,14 @@ public void modifyText( ModifyEvent e ) {
void createDesciptionTab(CTabFolder mainTabFolder) {
descTabItem = new CTabItem(mainTabFolder, SWT.NONE);
descTabItem.setText(Messages.desciption);

Composite descPanel = new Composite(mainTabFolder, SWT.NONE);
GridLayoutFactory.fillDefaults().applyTo(descPanel);

// ===========>>>> Create Description Group
descriptionTextEditor = new StyledTextEditor(mainTabFolder, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
final GridData descGridData = new GridData(GridData.FILL_BOTH);
descGridData.horizontalSpan = 2;
descGridData.heightHint = 50;
descGridData.minimumHeight = 30;
descGridData.grabExcessVerticalSpace = true;
descriptionTextEditor.setLayoutData(descGridData);
descriptionTextEditor = new StyledTextEditor(descPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 60).minSize(SWT.DEFAULT, 30).applyTo(descriptionTextEditor.getTextWidget());

if( this.description != null ) {
descriptionTextEditor.setText(this.description);
} else {
Expand All @@ -275,8 +281,8 @@ public void documentAboutToBeChanged( DocumentEvent event ) {
// NO OP
}
});

descTabItem.setControl(descriptionTextEditor.getTextWidget());
descTabItem.setControl(descPanel);
}

void createPermissionsTab(CTabFolder mainTabFolder) {
Expand Down Expand Up @@ -617,36 +623,32 @@ private void handleDescriptionChanged() {


public DataRole getFinalDataRole() {
if (existingDataRole == null) {
existingDataRole = new DataRole(this.dataRoleName);
}

existingDataRole.setName(this.dataRoleName);
existingDataRole.setAnyAuthenticated(this.anyAuthentication);
existingDataRole.setAllowCreateTempTables(this.allowCreateTempTables);
existingDataRole.setGrantAll(this.grantAll);
existingDataRole.setDescription(this.description);
existingDataRole.setPermissions(this.treeProvider.getPermissions());
editedDataRole.setName(this.dataRoleName);
editedDataRole.setAnyAuthenticated(this.anyAuthentication);
editedDataRole.setAllowCreateTempTables(this.allowCreateTempTables);
editedDataRole.setGrantAll(this.grantAll);
editedDataRole.setDescription(this.description);
editedDataRole.setPermissions(this.treeProvider.getPermissions());

Permission systemPerm = existingDataRole.getPermission(SYS_ADMIN_TABLE_TARGET);
Permission systemPerm = editedDataRole.getPermission(SYS_ADMIN_TABLE_TARGET);
if (allowSystemTables ) {
if( systemPerm == null ) {
existingDataRole.addPermission(new Permission(SYS_ADMIN_TABLE_TARGET,
editedDataRole.addPermission(new Permission(SYS_ADMIN_TABLE_TARGET,
false, allowSystemRead, false,
false, allowSystemExecute, false));
}
} else {
if( systemPerm != null ) {
existingDataRole.removePermission(systemPerm);
editedDataRole.removePermission(systemPerm);
}
}
if (!this.anyAuthentication && !mappedRoleNames.isEmpty()) {
existingDataRole.setRoleNames(mappedRoleNames);
editedDataRole.setRoleNames(mappedRoleNames);
} else {
existingDataRole.getRoleNames().clear();
editedDataRole.getRoleNames().clear();
}

return this.existingDataRole;
return this.editedDataRole;
}

public DataRolesModelTreeProvider getTreeProvider() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,44 +579,51 @@ private Composite createEditorBottom( Composite parent ) {
CTabFolder tabFolder = WidgetFactory.createTabFolder(pnlBottom);

{ // roles tab
CTabItem rolesTab = new CTabItem(tabFolder, SWT.NONE);
rolesTab.setText(i18n("rolesTab")); //$NON-NLS-1$
rolesTab.setToolTipText(i18n("rolesTabToolTip")); //$NON-NLS-1$
Composite pnlRoles = new Composite(tabFolder, SWT.NONE);
pnlRoles.setLayout(new GridLayout());
pnlRoles.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
rolesTab.setControl(pnlRoles);
dataRolesPanel = new DataRolesPanel(pnlRoles, this);
CTabItem theTab = new CTabItem(tabFolder, SWT.NONE);
theTab.setText(i18n("rolesTab")); //$NON-NLS-1$
theTab.setToolTipText(i18n("rolesTabToolTip")); //$NON-NLS-1$
Composite tabPanel = new Composite(tabFolder, SWT.NONE);
tabPanel.setLayout(new GridLayout());
tabPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
theTab.setControl(tabPanel);
dataRolesPanel = new DataRolesPanel(tabPanel, this);
theTab.setControl(tabPanel);
tabPanel.layout();
}

{ // properties tab
CTabItem propertiesTab = new CTabItem(tabFolder, SWT.NONE);
propertiesTab.setText(i18n("propertiesTab")); //$NON-NLS-1$
propertiesTab.setToolTipText(i18n("propertiesTabToolTip")); //$NON-NLS-1$
Composite pnlProperties = new Composite(tabFolder, SWT.NONE);
pnlProperties.setLayout(new GridLayout());
pnlProperties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
propertiesTab.setControl(pnlProperties);
propertiesPanel = new PropertiesPanel(pnlProperties, getVdb());
CTabItem theTab = new CTabItem(tabFolder, SWT.NONE);
theTab.setText(i18n("propertiesTab")); //$NON-NLS-1$
theTab.setToolTipText(i18n("propertiesTabToolTip")); //$NON-NLS-1$
Composite tabPanel = new Composite(tabFolder, SWT.NONE);
tabPanel.setLayout(new GridLayout());
tabPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
theTab.setControl(tabPanel);
propertiesPanel = new PropertiesPanel(tabPanel, getVdb());
theTab.setControl(tabPanel);
tabPanel.layout();
}

{ // properties tab
CTabItem tab = new CTabItem(tabFolder, SWT.NONE);
tab.setText(i18n("userDefinedPropertiesTab")); //$NON-NLS-1$
tab.setToolTipText(i18n("userDefinedPropertiesTabToolTip")); //$NON-NLS-1$
Composite pnlProperties = new Composite(tabFolder, SWT.NONE);
pnlProperties.setLayout(new GridLayout());
pnlProperties.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tab.setControl(pnlProperties);
userDefinedPropertiesPanel = new UserDefinedPropertiesPanel(pnlProperties, getVdb());
CTabItem theTab = new CTabItem(tabFolder, SWT.NONE);
theTab.setText(i18n("userDefinedPropertiesTab")); //$NON-NLS-1$
theTab.setToolTipText(i18n("userDefinedPropertiesTabToolTip")); //$NON-NLS-1$
Composite tabPanel = new Composite(tabFolder, SWT.NONE);
tabPanel.setLayout(new GridLayout());
tabPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
theTab.setControl(tabPanel);
userDefinedPropertiesPanel = new UserDefinedPropertiesPanel(tabPanel, getVdb());
theTab.setControl(tabPanel);
tabPanel.layout();
}

{ // translator overrides tab
CTabItem translatorOverridesTab = new CTabItem(tabFolder, SWT.NONE);
translatorOverridesTab.setText(i18n("translatorOverridesTab")); //$NON-NLS-1$
translatorOverridesTab.setToolTipText(i18n("translatorOverridesTabToolTip")); //$NON-NLS-1$
CTabItem theTab = new CTabItem(tabFolder, SWT.NONE);
theTab.setText(i18n("translatorOverridesTab")); //$NON-NLS-1$
theTab.setToolTipText(i18n("translatorOverridesTabToolTip")); //$NON-NLS-1$
pnlTranslatorOverrides = new TranslatorOverridesPanel(tabFolder, this.vdb);
translatorOverridesTab.setControl(pnlTranslatorOverrides);
theTab.setControl(pnlTranslatorOverrides);
pnlTranslatorOverrides.layout();
}

tabFolder.setSelection(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IWorkbenchWindow;
import org.teiid.core.designer.util.StringConstants;
import org.teiid.designer.core.ModelEditorImpl;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.container.ContainerImpl;
Expand All @@ -35,6 +36,8 @@
import org.teiid.designer.metamodels.relational.RelationalPackage;
import org.teiid.designer.metamodels.xml.XmlDocumentPackage;
import org.teiid.designer.roles.DataRole;
import org.teiid.designer.roles.Permission;
import org.teiid.designer.roles.Crud.Type;
import org.teiid.designer.roles.ui.wizard.DataRoleWizard;
import org.teiid.designer.ui.common.table.DefaultTableProvider;
import org.teiid.designer.ui.common.table.TableAndToolBar;
Expand Down Expand Up @@ -178,8 +181,26 @@ public void selected( IStructuredSelection selection ) {
// Get the Data Policy
DataRole dp = wizard.getFinalDataRole();
if (dp != null) {
vdbEditor.getVdb().removeDataRole(dataRole.getName());
vdbEditor.getVdb().addDataRole(dp);
if( !vdbEditor.getVdb().getDataRoles().contains(dp) ) {
dataRole.setName(dp.getName());
dataRole.setAnyAuthenticated(dp.isAnyAuthenticated());
dataRole.setAllowCreateTempTables(dp.isAllowCreateTempTables());
dataRole.setGrantAll(dp.isGrantAll());
dataRole.setDescription(dp.getDescription());
dataRole.setPermissions(dp.getPermissions());

Permission systemPerm = dataRole.getPermission(DataRole.SYS_ADMIN_TABLE_TARGET);
if( systemPerm != null ) {
dataRole.addPermission(new Permission(DataRole.SYS_ADMIN_TABLE_TARGET,
false, systemPerm.getCRUDValue(Type.READ).booleanValue(), false,
false, systemPerm.getCRUDValue(Type.EXECUTE).booleanValue(), false));
}
if (!dataRole.isAnyAuthenticated() && !dp.getRoleNames().isEmpty()) {
dataRole.setRoleNames(dp.getRoleNames());
}

refresh();
}
}

}
Expand Down Expand Up @@ -285,6 +306,7 @@ public Image getImage() {
*/
@Override
public String getValue( final DataRole element ) {
if( element.getDescription() == null ) return StringConstants.EMPTY_STRING;
return element.getDescription();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ public class DataRole extends VdbUnit {
/**
* The default value for the <code>create temporary tables</code> property. Value is {@value} .
*/
boolean DEFAULT_ALLOW_CREATE_TEMP_TABLES = false;
public boolean DEFAULT_ALLOW_CREATE_TEMP_TABLES = false;

/**
* The default value for the <code>any authenticated</code> property. Value is {@value} .
*/
boolean DEFAULT_ANY_AUTHENTICATED = false;
public boolean DEFAULT_ANY_AUTHENTICATED = false;

/**
* The default value for the <code>grant all</code> property. Value is {@value} .
*/
boolean DEFAULT_GRANT_ALL = false;
public boolean DEFAULT_GRANT_ALL = false;

@SuppressWarnings("javadoc")
public static final String SYS_ADMIN_TABLE_TARGET = "sysadmin"; //$NON-NLS-1$
@SuppressWarnings("javadoc")
public static final String SYS_TABLE_TARGET = "sys"; //$NON-NLS-1$

/**
* An empty array of data roles.
Expand Down

0 comments on commit f15c61e

Please sign in to comment.