-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce View Container and base view components #338
Merged
+350
−134
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
13c55ac
improved handling of lsp failure state
548a9da
add static mock to lsp connection test case
374e549
Integrate Event Broker in LspStatusManager
taldekar 6a9f8d3
Add ViewRouter POC
taldekar d1746a4
Fix code formatting bug
taldekar 991b319
commiting POC
cca4f55
addition of view container and updated base view
028a7a5
convert view container set up to feature viewId enum
a053f7e
remove unused import
8ac51f0
checkstyle edits
ceae903
translated base view to abstract class and changed lsp failure view t…
24e1b96
add missing header styling to base views
74707ad
Merge branch 'feature/viewRefactor' into nickdb/viewContainerSetup
nborges-aws d18421e
removed old viewId class and update view rendering logic
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQViewContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.views; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.custom.StackLayout; | ||
import org.eclipse.swt.layout.GridData; | ||
import org.eclipse.swt.layout.GridLayout; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.ui.part.ViewPart; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.broker.api.EventObserver; | ||
import software.aws.toolkits.eclipse.amazonq.plugin.Activator; | ||
import software.aws.toolkits.eclipse.amazonq.views.actions.AmazonQStaticActions; | ||
import software.aws.toolkits.eclipse.amazonq.views.router.AmazonQViewType; | ||
|
||
|
||
public final class AmazonQViewContainer extends ViewPart implements EventObserver<AmazonQViewType> { | ||
private Composite parentComposite; | ||
private StackLayout layout; | ||
private Map<AmazonQViewType, BaseAmazonQView> views; | ||
private AmazonQViewType activeId; | ||
private BaseAmazonQView activeView; | ||
|
||
public AmazonQViewContainer() { | ||
Activator.getEventBroker().subscribe(AmazonQViewType.class, this); | ||
} | ||
|
||
/* Router should be initialized, then init view container | ||
* ViewRouter.Initialize() | ||
* viewcontainer.init(activeViewId) | ||
*/ | ||
|
||
/* | ||
* When container is disposed and being reopened, class will be recreated | ||
* need to call showView to reset viewContainer && follow up with init call to container | ||
* 1. showView(viewContainer.ID) | ||
* 2. viewContainer.init(currentView) | ||
*/ | ||
|
||
public void initializeViews(final AmazonQViewType currentActiveViewId) { | ||
|
||
//init map containing all views | ||
var dependencyMissingView = new DependencyMissingView(); | ||
var chatAssetMissingView = new ChatAssetMissingView(); | ||
var reAuthView = new ReauthenticateView(); | ||
var lspFailedView = new LspStartUpFailedView(); | ||
views = Map.of( | ||
AmazonQViewType.CHAT_ASSET_MISSING_VIEW, chatAssetMissingView, | ||
AmazonQViewType.DEPENDENCY_MISSING_VIEW, dependencyMissingView, | ||
AmazonQViewType.RE_AUTHENTICATE_VIEW, reAuthView, | ||
AmazonQViewType.LSP_STARTUP_FAILED_VIEW, lspFailedView | ||
); | ||
|
||
//default view passed in from router | ||
//possible we'll use chatView as default? | ||
activeId = currentActiveViewId; | ||
} | ||
|
||
public void createPartControl(final Composite parent) { | ||
parentComposite = parent; | ||
layout = new StackLayout(); | ||
parent.setLayout(layout); | ||
|
||
//add base stylings | ||
GridLayout gridLayout = new GridLayout(1, false); | ||
gridLayout.marginLeft = 20; | ||
gridLayout.marginRight = 20; | ||
gridLayout.marginTop = 10; | ||
gridLayout.marginBottom = 10; | ||
parent.setLayout(gridLayout); | ||
|
||
setupStaticMenuActions(); | ||
updateChildView(); | ||
} | ||
|
||
/* change methodology for setupMenuActions -- move outside of viewContainer? | ||
* will need ability to switch between the two based on which view is displaying && authState | ||
* if viewId = static view --> new AmazonQStaticActions(getViewSite()); | ||
* if viewId = common view --> new AmazonQCommonActions(AuthState, getViewSite()); | ||
*/ | ||
private void setupStaticMenuActions() { | ||
new AmazonQStaticActions(getViewSite()); | ||
} | ||
|
||
private void updateChildView() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There might be race condition if both the createPartControl and onEvent call these methods simultaneously. |
||
Display.getDefault().asyncExec(() -> { | ||
BaseAmazonQView newView = views.get(activeId); | ||
|
||
if (activeView != null) { | ||
activeView.dispose(); | ||
if (layout.topControl != null) { | ||
layout.topControl.dispose(); | ||
} | ||
} | ||
|
||
Composite newViewComposite = newView.setupView(parentComposite); | ||
GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true); | ||
newViewComposite.setLayoutData(gridData); | ||
|
||
layout.topControl = newViewComposite; | ||
parentComposite.layout(true, true); | ||
|
||
activeView = newView; | ||
}); | ||
} | ||
|
||
@Override | ||
public void onEvent(final AmazonQViewType newViewId) { | ||
if (newViewId.equals(activeId) || !views.containsKey(newViewId)) { | ||
return; | ||
} | ||
activeId = newViewId; | ||
|
||
if (!parentComposite.isDisposed()) { | ||
updateChildView(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setFocus() { | ||
parentComposite.setFocus(); | ||
|
||
} | ||
|
||
@Override | ||
public void dispose() { | ||
if (activeView != null) { | ||
activeView.dispose(); | ||
} | ||
super.dispose(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
plugin/src/software/aws/toolkits/eclipse/amazonq/views/BaseAmazonQView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.views; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import org.eclipse.swt.graphics.Font; | ||
import org.eclipse.swt.graphics.FontData; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.widgets.Composite; | ||
import org.eclipse.swt.widgets.Display; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.plugin.Activator; | ||
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils; | ||
|
||
public abstract class BaseAmazonQView { | ||
public abstract Composite setupView(Composite parentComposite); | ||
public abstract void dispose(); | ||
|
||
protected Image loadImage(final String imagePath) { | ||
Image loadedImage = null; | ||
try { | ||
URL imageUrl = PluginUtils.getResource(imagePath); | ||
if (imageUrl != null) { | ||
loadedImage = new Image(Display.getCurrent(), imageUrl.openStream()); | ||
} | ||
} catch (IOException e) { | ||
Activator.getLogger().warn(e.getMessage(), e); | ||
} | ||
return loadedImage; | ||
} | ||
protected Font magnifyFontSize(final Composite parentComposite, final Font originalFont, final int fontSize) { | ||
FontData[] fontData = originalFont.getFontData(); | ||
for (int i = 0; i < fontData.length; i++) { | ||
fontData[i].setHeight(fontSize); | ||
} | ||
Font magnifiedFont = new Font(parentComposite.getDisplay(), fontData); | ||
return magnifiedFont; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this to the constructor?