1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for Bug 214806

New canWriteExpression() method is added to IExpressions and is used
to know if the user should be given the option to edit the value of an expression
in the views.
This commit is contained in:
Marc Khouzam 2008-02-08 20:58:49 +00:00
parent 857c836ecf
commit 8fda4772aa
3 changed files with 112 additions and 21 deletions

View file

@ -106,7 +106,7 @@ public class SyncVariableDataAccess {
@Override @Override
protected void execute(final DataRequestMonitor<IExpressionDMData> rm) { protected void execute(final DataRequestMonitor<IExpressionDMData> rm) {
/* /*
* Guard agains the session being disposed. If session is disposed * Guard against the session being disposed. If session is disposed
* it could mean that the executor is shut-down, which in turn could * it could mean that the executor is shut-down, which in turn could
* mean that we can't complete the RequestMonitor argument. in that * mean that we can't complete the RequestMonitor argument. in that
* case, cancel to notify waiting thread. * case, cancel to notify waiting thread.
@ -159,7 +159,7 @@ public class SyncVariableDataAccess {
public IExpressionDMData readVariable(Object element) { public IExpressionDMData readVariable(Object element) {
/* /*
* Get the DMC and the session. If element is not an register DMC, or * Get the DMC and the session. If element is not an expression DMC, or
* session is stale, then bail out. * session is stale, then bail out.
*/ */
IExpressionDMContext dmc = getExpressionDMC(element); IExpressionDMContext dmc = getExpressionDMC(element);
@ -169,7 +169,7 @@ public class SyncVariableDataAccess {
/* /*
* Create the query to request the value from service. Note: no need to * Create the query to request the value from service. Note: no need to
* guard agains RejectedExecutionException, because * guard against RejectedExecutionException, because
* DsfSession.getSession() above would only return an active session. * DsfSession.getSession() above would only return an active session.
*/ */
GetVariableValueQuery query = new GetVariableValueQuery(dmc); GetVariableValueQuery query = new GetVariableValueQuery(dmc);
@ -226,7 +226,7 @@ public class SyncVariableDataAccess {
} }
/* /*
* Write the bit field using a string/format style. * Write the expression value using a string/format style.
*/ */
service.writeExpression( service.writeExpression(
fDmc, fDmc,
@ -272,7 +272,7 @@ public class SyncVariableDataAccess {
/* /*
* Create the query to write the value to the service. Note: no need to * Create the query to write the value to the service. Note: no need to
* guard agains RejectedExecutionException, because * guard against RejectedExecutionException, because
* DsfSession.getSession() above would only return an active session. * DsfSession.getSession() above would only return an active session.
*/ */
SetVariableValueQuery query = new SetVariableValueQuery(dmc, value, formatId); SetVariableValueQuery query = new SetVariableValueQuery(dmc, value, formatId);
@ -337,7 +337,7 @@ public class SyncVariableDataAccess {
} }
/* /*
* Write the bit field using a string/format style. * Get the available formats from the service.
*/ */
service.getAvailableFormats( service.getAvailableFormats(
fDmc, fDmc,
@ -381,7 +381,7 @@ public class SyncVariableDataAccess {
/* /*
* Create the query to write the value to the service. Note: no need to * Create the query to write the value to the service. Note: no need to
* guard agains RejectedExecutionException, because * guard against RejectedExecutionException, because
* DsfSession.getSession() above would only return an active session. * DsfSession.getSession() above would only return an active session.
*/ */
GetSupportFormatsValueQuery query = new GetSupportFormatsValueQuery(dmc); GetSupportFormatsValueQuery query = new GetSupportFormatsValueQuery(dmc);
@ -479,7 +479,7 @@ public class SyncVariableDataAccess {
/* /*
* Create the query to write the value to the service. Note: no need to * Create the query to write the value to the service. Note: no need to
* guard agains RejectedExecutionException, because * guard against RejectedExecutionException, because
* DsfSession.getSession() above would only return an active session. * DsfSession.getSession() above would only return an active session.
*/ */
GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(dmc, formatId); GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(dmc, formatId);
@ -499,4 +499,95 @@ public class SyncVariableDataAccess {
return null; return null;
} }
} }
private class CanWriteExpressionQuery extends Query<Boolean> {
private IExpressionDMContext fDmc;
public CanWriteExpressionQuery(IExpressionDMContext dmc) {
super();
fDmc = dmc;
}
@Override
protected void execute(final DataRequestMonitor<Boolean> rm) {
/*
* We're in another dispatch, so we must guard against executor
* shutdown again.
*/
final DsfSession session = DsfSession.getSession(fDmc.getSessionId());
if (session == null) {
cancel(false);
return;
}
/*
* Guard against a disposed service
*/
IExpressions service = getService();
if (service == null) {
rm .setStatus(new Status(IStatus.ERROR, DsfDebugUIPlugin.PLUGIN_ID, IDsfService.INVALID_STATE, "Service unavailable", null)); //$NON-NLS-1$
rm.done();
return;
}
service.canWriteExpression(fDmc, new DataRequestMonitor<Boolean>(session.getExecutor(), rm) {
@Override
protected void handleCompleted() {
/*
* We're in another dispatch, so we must guard against executor shutdown again.
*/
if (!DsfSession.isSessionActive(session.getId())) {
CanWriteExpressionQuery.this.cancel(false);
return;
}
super.handleCompleted();
}
@Override
protected void handleOK() {
/*
* All good set return value.
*/
rm.setData(getData());
rm.done();
}
});
}
}
public boolean canWriteExpression(Object element) {
/*
* Get the DMC and the session. If element is not an expression DMC, or
* session is stale, then bail out.
*/
IExpressionDMContext dmc = getExpressionDMC(element);
if (dmc == null) return false;
DsfSession session = DsfSession.getSession(dmc.getSessionId());
if (session == null) return false;
/*
* Create the query to make the request to the service. Note: no need to
* guard against RejectedExecutionException, because
* DsfSession.getSession() above would only return an active session.
*/
CanWriteExpressionQuery query = new CanWriteExpressionQuery(dmc);
session.getExecutor().execute(query);
/*
* Now we have the data, go and get it. Since the call is completed now
* the ".get()" will not suspend it will immediately return with the
* data.
*/
try {
return query.get();
} catch (InterruptedException e) {
assert false;
return false;
} catch (ExecutionException e) {
return false;
}
}
} }

View file

@ -9,7 +9,6 @@ package org.eclipse.dd.dsf.debug.ui.viewmodel.variable;
import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.dd.dsf.debug.service.IFormattedValues; import org.eclipse.dd.dsf.debug.service.IFormattedValues;
import org.eclipse.dd.dsf.debug.service.IExpressions.IExpressionDMContext; import org.eclipse.dd.dsf.debug.service.IExpressions.IExpressionDMContext;
import org.eclipse.dd.dsf.debug.service.IExpressions.IExpressionDMData;
import org.eclipse.dd.dsf.debug.ui.viewmodel.IDebugVMConstants; import org.eclipse.dd.dsf.debug.ui.viewmodel.IDebugVMConstants;
import org.eclipse.dd.dsf.debug.ui.viewmodel.expression.WatchExpressionCellModifier; import org.eclipse.dd.dsf.debug.ui.viewmodel.expression.WatchExpressionCellModifier;
import org.eclipse.dd.dsf.debug.ui.viewmodel.numberformat.IFormattedValuePreferenceStore; import org.eclipse.dd.dsf.debug.ui.viewmodel.numberformat.IFormattedValuePreferenceStore;
@ -51,14 +50,11 @@ public class VariableCellModifier extends WatchExpressionCellModifier {
if (IDebugVMConstants.COLUMN_ID__VALUE.equals(property)) { if (IDebugVMConstants.COLUMN_ID__VALUE.equals(property)) {
// Make sure we are are dealing with a valid set of information. // Make sure we are are dealing with a valid set of information.
if (getVariableDMC(element) == null) if (getVariableDMC(element) == null) {
return false; return false;
}
IExpressionDMData exprData = fDataAccess.readVariable(element); return fDataAccess.canWriteExpression(element);
if ( ( exprData != null ) && ( ! exprData.isEditable() ) ) return false;
return true ;
} }
return super.canModify(element, property); return super.canModify(element, property);

View file

@ -121,12 +121,7 @@ public interface IExpressions extends IFormattedValues {
/** /**
* This method needs to be defined. * This method needs to be defined.
*/ */
IRegisters.IRegisterDMContext getRegister(); IRegisters.IRegisterDMContext getRegister();
/**
* @return True if this expression's value can be edited. False otherwise.
*/
boolean isEditable();
} }
/** /**
@ -217,6 +212,15 @@ public interface IExpressions extends IFormattedValues {
*/ */
void getBaseExpressions(IExpressionDMContext exprContext, DataRequestMonitor<IExpressionDMContext[]> rm); void getBaseExpressions(IExpressionDMContext exprContext, DataRequestMonitor<IExpressionDMContext[]> rm);
/**
* This method indicates if an expression can be written to.
*
* @param expressionContext: The data model context representing an expression.
*
* @param rm: Data Request monitor containing True if this expression's value can be edited. False otherwise.
*/
void canWriteExpression(IExpressionDMContext expressionContext, DataRequestMonitor<Boolean> rm);
/** /**
* This method supports the writing/modifying the value of the expression. * This method supports the writing/modifying the value of the expression.
* *