Commit a3f077f3 authored by azara's avatar azara
Browse files

BS-9316

"Create document" shortcut is not available
parent d4fdf5d8
......@@ -4,7 +4,7 @@
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*
* Contributors:
* IBM Corporation - initial API and implementation
* Hannes Erven <hannes@erven.at> - Bug 293841 - [FieldAssist] NumLock keyDown event should not close the proposal popup [with patch]
......@@ -83,7 +83,7 @@ import org.eclipse.swt.widgets.Text;
* activated, and whether any filtering should be done on the proposals as the user types characters.
* <p>
* This class provides some overridable methods to allow clients to manually control the popup. However, most of the implementation remains private.
*
*
* @since 3.2
*/
public class BonitaContentProposalAdapter implements SWTBotConstants {
......@@ -109,9 +109,10 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
private boolean scrollbarClicked = false;
@Override
public void handleEvent(final Event e) {
int width = getControl().getBounds().width;
final int width = getControl().getBounds().width;
if (e.x >= width - 18 && e.x <= width - 12 && e.y >= 8 && e.y <= 12) {
return;
}
......@@ -128,6 +129,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
*/
e.display.asyncExec(new Runnable() {
@Override
public void run() {
if (isValid()) {
if (scrollbarClicked || hasFocus()) {
......@@ -138,7 +140,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
// This can happen, for example, when resizing
// the popup shell on the Mac.
// Check the active shell.
Shell activeShell = e.display.getActiveShell();
final Shell activeShell = e.display.getActiveShell();
if (activeShell == getShell() || (infoPopup != null && infoPopup.getShell() == activeShell) || linkClicked) {
return;
}
......@@ -176,7 +178,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
void installListeners() {
// Listeners on this popup's table and scroll bar
proposalTable.addListener(SWT.FocusOut, this);
ScrollBar scrollbar = proposalTable.getVerticalBar();
final ScrollBar scrollbar = proposalTable.getVerticalBar();
if (scrollbar != null) {
scrollbar.addListener(SWT.Selection, this);
}
......@@ -191,7 +193,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
control.addListener(SWT.Dispose, this);
control.addListener(SWT.FocusOut, this);
// Listeners on the target control's shell
Shell controlShell = control.getShell();
final Shell controlShell = control.getShell();
controlShell.addListener(SWT.Move, this);
controlShell.addListener(SWT.Resize, this);
......@@ -201,7 +203,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
void removeListeners() {
if (isValid()) {
proposalTable.removeListener(SWT.FocusOut, this);
ScrollBar scrollbar = proposalTable.getVerticalBar();
final ScrollBar scrollbar = proposalTable.getVerticalBar();
if (scrollbar != null) {
scrollbar.removeListener(SWT.Selection, this);
}
......@@ -217,7 +219,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
control.removeListener(SWT.Dispose, this);
control.removeListener(SWT.FocusOut, this);
Shell controlShell = control.getShell();
final Shell controlShell = control.getShell();
controlShell.removeListener(SWT.Move, this);
controlShell.removeListener(SWT.Resize, this);
}
......@@ -230,12 +232,13 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
private final class TargetControlListener implements Listener {
// Key events from the control
public void handleEvent(Event e) {
@Override
public void handleEvent(final Event e) {
if (!isValid()) {
return;
}
char key = e.character;
final char key = e.character;
// Traverse events are handled depending on whether the
// event has a character.
......@@ -265,7 +268,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
if (key == 0) {
int newSelection = proposalTable.getSelectionIndex();
int visibleRows = (proposalTable.getSize().y / proposalTable.getItemHeight()) - 1;
final int visibleRows = (proposalTable.getSize().y / proposalTable.getItemHeight()) - 1;
switch (e.keyCode) {
case SWT.ARROW_UP:
newSelection -= 1;
......@@ -333,17 +336,17 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
}
break;
// If received as a Traverse, these should propagate
// to the control as keydown. If received as a keydown,
// proposals should be recomputed since the cursor
// position has changed.
// If received as a Traverse, these should propagate
// to the control as keydown. If received as a keydown,
// proposals should be recomputed since the cursor
// position has changed.
case SWT.ARROW_LEFT:
case SWT.ARROW_RIGHT:
if (e.type == SWT.Traverse) {
e.doit = false;
} else {
e.doit = true;
String contents = getControlContentAdapter().getControlContents(getControl());
final String contents = getControlContentAdapter().getControlContents(getControl());
// If there are no contents, changes in cursor
// position have no effect. Note also that we do
// not affect the filter text on ARROW_LEFT as
......@@ -354,12 +357,12 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
}
break;
// Any unknown keycodes will cause the popup to close.
// Modifier keys are explicitly checked and ignored because
// they are not complete yet (no character).
// Any unknown keycodes will cause the popup to close.
// Modifier keys are explicitly checked and ignored because
// they are not complete yet (no character).
default:
if (e.keyCode != SWT.CAPS_LOCK && e.keyCode != SWT.NUM_LOCK && e.keyCode != SWT.MOD1
&& e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) {
&& e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4) {
close();
}
return;
......@@ -385,7 +388,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
case SWT.LF:
case SWT.CR:
e.doit = false;
Object p = getSelectedProposal();
final Object p = getSelectedProposal();
if (p != null) {
acceptCurrentProposal();
} else {
......@@ -414,7 +417,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
// clients provide their own filtering based on content.
// Recompute the proposals if the cursor position
// will change (is not at 0).
int pos = getControlContentAdapter().getCursorPosition(getControl());
final int pos = getControlContentAdapter().getCursorPosition(getControl());
// We rely on the fact that the contents and pos do not yet
// reflect the result of the BS. If the contents were
// already empty, then BS should not cause
......@@ -460,18 +463,19 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
/*
* Construct an info-popup with the specified parent.
*/
InfoPopupDialog(Shell parent) {
InfoPopupDialog(final Shell parent) {
super(parent, PopupDialog.HOVER_SHELLSTYLE, false, false, false, false, false, null, null);
}
/*
* Create a text control for showing the info about a proposal.
*/
protected Control createDialogArea(Composite parent) {
@Override
protected Control createDialogArea(final Composite parent) {
text = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.NO_FOCUS);
// Use the compact margins employed by PopupDialog.
GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
final GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
text.setLayoutData(gd);
......@@ -480,7 +484,8 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
// since SWT.NO_FOCUS is only a hint...
text.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
@Override
public void focusGained(final FocusEvent event) {
ContentProposalPopup.this.close();
}
});
......@@ -490,8 +495,9 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
/*
* Adjust the bounds so that we appear adjacent to our parent shell
*/
@Override
protected void adjustBounds() {
Rectangle parentBounds = getParentShell().getBounds();
final Rectangle parentBounds = getParentShell().getBounds();
Rectangle proposedBounds;
// Try placing the info popup to the right
Rectangle rightProposedBounds = new Rectangle(parentBounds.x + parentBounds.width
......@@ -529,6 +535,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.PopupDialog#getForeground()
*/
@Override
protected Color getForeground() {
return control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
}
......@@ -537,6 +544,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.PopupDialog#getBackground()
*/
@Override
protected Color getBackground() {
return control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
}
......@@ -548,7 +556,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
if (newContents == null) {
newContents = EMPTY;
}
this.contents = newContents;
contents = newContents;
if (text != null && !text.isDisposed()) {
text.setText(contents);
}
......@@ -610,11 +618,11 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* Constructs a new instance of this popup, specifying the control for
* which this popup is showing content, and how the proposals should be
* obtained and displayed.
*
*
* @param infoText
* Text to be shown in a lower info area, or <code>null</code> if there is no info area.
*/
ContentProposalPopup(String infoText, IContentProposal[] proposals) {
ContentProposalPopup(final String infoText, final IContentProposal[] proposals) {
// IMPORTANT: Use of SWT.ON_TOP is critical here for ensuring
// that the target control retains focus on Mac and Linux. Without
// it, the focus will disappear, keystrokes will not go to the
......@@ -627,7 +635,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
}
@Override
protected void configureShell(Shell shell) {
protected void configureShell(final Shell shell) {
super.configureShell(shell);
shell.setData(SWTBOT_WIDGET_ID_KEY, SWTBOT_ID_EXPRESSIONVIEWER_PROPOSAL_SHELL);
}
......@@ -636,6 +644,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.PopupDialog#getForeground()
*/
@Override
protected Color getForeground() {
return JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_FOREGROUND_COLOR);
}
......@@ -644,6 +653,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.PopupDialog#getBackground()
*/
@Override
protected Color getBackground() {
return JFaceResources.getColorRegistry().get(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR);
}
......@@ -655,6 +665,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* @param parent The parent composite to contain the dialog area; must
* not be <code>null</code>.
*/
@Override
protected final Control createDialogArea(final Composite parent) {
createProposalTable(parent);
createVariableCreationZone(parent);
......@@ -668,9 +679,10 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
proposalTableComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
if (USE_VIRTUAL) {
proposalTable = new Table(proposalTableComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL);
Listener listener = new Listener() {
final Listener listener = new Listener() {
public void handleEvent(Event event) {
@Override
public void handleEvent(final Event event) {
handleSetData(event);
}
};
......@@ -685,7 +697,8 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
proposalTable.setHeaderVisible(false);
proposalTable.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
@Override
public void widgetSelected(final SelectionEvent e) {
// If a proposal has been selected, show it in the secondary
// popup. Otherwise close the popup.
if (e.item == null) {
......@@ -698,7 +711,8 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
}
// Default selection was made. Accept the current proposal.
public void widgetDefaultSelected(SelectionEvent e) {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
acceptCurrentProposal();
}
});
......@@ -711,7 +725,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
creationZoneComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
Link createDataLink;
for (IConfigurationElement element : getProposalListeners()) {
for (final IConfigurationElement element : getProposalListeners()) {
final String expressionTypeLink = element.getAttribute("type");
if (!filteredExpressionType.contains(expressionTypeLink)) {
createDataLink = new Link(creationZoneComposite, SWT.NONE);
......@@ -722,14 +736,14 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
createDataLink.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
public void widgetSelected(final SelectionEvent e) {
linkClicked = true;
updateExpressionField(addNewData(listener));
linkClicked = false;
}
});
} catch (CoreException e) {
} catch (final CoreException e) {
BonitaStudioLog.error(e);
}
linkList.add(createDataLink);
......@@ -740,36 +754,38 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
}
private IConfigurationElement[] getProposalListeners() {
IConfigurationElement[] configurationElements = BonitaStudioExtensionRegistryManager.getInstance()
final IConfigurationElement[] configurationElements = BonitaStudioExtensionRegistryManager.getInstance()
.getConfigurationElements("org.bonitasoft.studio.expression.proposalListener");
List<IConfigurationElement> elements = new ArrayList<IConfigurationElement>();
final List<IConfigurationElement> elements = new ArrayList<IConfigurationElement>();
// Filters duplicates
Set<String> expressionTypes = new HashSet<String>();
for (IConfigurationElement e : configurationElements) {
String type = e.getAttribute("type");
final Set<String> expressionTypes = new HashSet<String>();
for (final IConfigurationElement e : configurationElements) {
final String type = e.getAttribute("type");
if (type.equals(ExpressionConstants.DOCUMENT_REF_TYPE) && expressionTypes.contains(ExpressionConstants.DOCUMENT_TYPE)) {
continue;
} else if (type.equals(ExpressionConstants.DOCUMENT_TYPE) && expressionTypes.contains(ExpressionConstants.DOCUMENT_REF_TYPE)) {
continue;
}
expressionTypes.add(type);
elements.add(e);
if (!filteredExpressionType.contains(type)) {
expressionTypes.add(type);
elements.add(e);
}
}
return elements.toArray(new IConfigurationElement[elements.size()]);
}
private void updateExpressionField(String newObjectLabel) {
private void updateExpressionField(final String newObjectLabel) {
if (newObjectLabel != null) {
final Object[] listenerArray = proposalListeners.getListeners();
for (int i = 0; i < listenerArray.length; i++) {
IContentProposalListener listener = (IContentProposalListener) listenerArray[i];
final IContentProposalListener listener = (IContentProposalListener) listenerArray[i];
if (listener instanceof ExpressionViewer) {
((ExpressionViewer) listener)
.manageNatureProviderAndAutocompletionProposal(((ExpressionViewer) listener).getInput());
.manageNatureProviderAndAutocompletionProposal(((ExpressionViewer) listener).getInput());
}
}
if (proposalProvider != null) {
IContentProposal[] newProposals = proposalProvider.getProposals("", 0);
final IContentProposal[] newProposals = proposalProvider.getProposals("", 0);
setProposals(newProposals);
for (int i = 0; i < newProposals.length; i++) {
if (newProposals[i].getContent().equals(newObjectLabel)) {
......@@ -785,15 +801,16 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.PopupDialog.adjustBounds()
*/
@Override
protected void adjustBounds() {
// Get our control's location in display coordinates.
Point location = control.getDisplay().map(control.getParent(), null, control.getLocation());
final Point location = control.getDisplay().map(control.getParent(), null, control.getLocation());
int initialX = location.x + POPUP_OFFSET;
int initialY = location.y + control.getSize().y + POPUP_OFFSET;
// If we are inserting content, use the cursor position to
// position the control.
if (getProposalAcceptanceStyle() == PROPOSAL_INSERT) {
Rectangle insertionBounds = controlContentAdapter.getInsertionBounds(control);
final Rectangle insertionBounds = controlContentAdapter.getInsertionBounds(control);
initialX = initialX + insertionBounds.x;
initialY = location.y + insertionBounds.y + insertionBounds.height;
}
......@@ -801,7 +818,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
// If there is no specified size, force it by setting
// up a layout on the table.
if (popupSize == null) {
GridData data = new GridData(GridData.FILL_BOTH);
final GridData data = new GridData(GridData.FILL_BOTH);
data.heightHint = proposalTable.getItemHeight() * POPUP_CHAR_HEIGHT;
data.widthHint = Math.max(control.getSize().x + TB_OFFSET, POPUP_MINIMUM_WIDTH);
proposalTable.setLayoutData(data);
......@@ -810,20 +827,22 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
}
// Constrain to the display
Rectangle constrainedBounds = getConstrainedShellBounds(new Rectangle(initialX, initialY, popupSize.x,
final Rectangle constrainedBounds = getConstrainedShellBounds(new Rectangle(initialX, initialY, popupSize.x,
popupSize.y));
// If there has been an adjustment causing the popup to overlap
// with the control, then put the popup above the control.
if (constrainedBounds.y < initialY)
if (constrainedBounds.y < initialY) {
getShell().setBounds(initialX, location.y - popupSize.y, popupSize.x, popupSize.y);
else
} else {
getShell().setBounds(initialX, initialY, popupSize.x, popupSize.y);
}
// Now set up a listener to monitor any changes in size.
getShell().addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
@Override
public void handleEvent(final Event e) {
popupSize = getShell().getSize();
if (infoPopup != null) {
infoPopup.adjustBounds();
......@@ -836,12 +855,12 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* Handle the set data event. Set the item data of the requested item to
* the corresponding proposal in the proposal cache.
*/
private void handleSetData(Event event) {
TableItem item = (TableItem) event.item;
int index = proposalTable.indexOf(item);
private void handleSetData(final Event event) {
final TableItem item = (TableItem) event.item;
final int index = proposalTable.indexOf(item);
if (0 <= index && index < proposals.length) {
IContentProposal current = proposals[index];
final IContentProposal current = proposals[index];
item.setText(getString(current));
item.setImage(getImage(current));
item.setData(current);
......@@ -859,7 +878,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
if (newProposals == null || newProposals.length == 0) {
newProposals = getEmptyProposalArray();
}
this.proposals = newProposals;
proposals = newProposals;
// If there is a table
if (isValid()) {
......@@ -873,10 +892,10 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
// Populate the table manually
proposalTable.setRedraw(false);
proposalTable.setItemCount(newSize);
TableItem[] items = proposalTable.getItems();
final TableItem[] items = proposalTable.getItems();
for (int i = 0; i < items.length; i++) {
TableItem item = items[i];
IContentProposal proposal = newProposals[i];
final TableItem item = items[i];
final IContentProposal proposal = newProposals[i];
item.setText(getString(proposal));
item.setImage(getImage(proposal));
item.setData(proposal);
......@@ -914,7 +933,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* Get the string for the specified proposal. Always return a String of
* some kind.
*/
private String getString(IContentProposal proposal) {
private String getString(final IContentProposal proposal) {
if (proposal == null) {
return EMPTY;
}
......@@ -928,7 +947,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* Get the image for the specified proposal. If there is no image
* available, return null.
*/
private Image getImage(IContentProposal proposal) {
private Image getImage(final IContentProposal proposal) {
if (proposal == null || labelProvider == null) {
return null;
}
......@@ -959,7 +978,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
if (!isValid()) {
return false;
}
for (Link l : linkList) {
for (final Link l : linkList) {
if (!l.isDisposed() && l.isFocusControl()) {
return true;
}
......@@ -978,7 +997,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
*/
private IContentProposal getSelectedProposal() {
if (isValid()) {
int i = proposalTable.getSelectionIndex();
final int i = proposalTable.getSelectionIndex();
if (proposals == null || i < 0 || i >= proposals.length) {
return null;
}
......@@ -990,7 +1009,7 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
/*
* Select the proposal at the given index.
*/
private void selectProposal(int index) {
private void selectProposal(final int index) {
Assert.isTrue(index >= 0, "Proposal index should never be negative"); //$NON-NLS-1$
if (!isValid() || proposals == null || index >= proposals.length) {
return;
......@@ -1005,18 +1024,19 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
* Opens this ContentProposalPopup. This method is extended in order to
* add the control listener when the popup is opened and to invoke the
* secondary popup if applicable.
*
*
* @return the return code
*
*
* @see org.eclipse.jface.window.Window#open()
*/
@Override
public int open() {
int value = super.open();
final int value = super.open();
if (popupCloser == null) {
popupCloser = new PopupCloserListener();
}
popupCloser.installListeners();
IContentProposal p = getSelectedProposal();
final IContentProposal p = getSelectedProposal();
if (p != null) {
showProposalDescription();
}
......@@ -1026,10 +1046,11 @@ public class BonitaContentProposalAdapter implements SWTBotConstants {
/**
* Closes this popup. This method is extended to remove the control
* listener.
*
*
* @return <code>true</code> if the window is (or was already) closed,
* and <code>false</code> if it is still open
*/