-
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
Notifications helper to show notifications #27
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
68 changes: 68 additions & 0 deletions
68
plugin/src/software/aws/toolkits/eclipse/amazonq/util/NotificationHelper.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,68 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.util; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.Image; | ||
import org.eclipse.swt.graphics.Point; | ||
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.swt.widgets.Label; | ||
import org.eclipse.ui.ISharedImages; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.jface.resource.ImageDescriptor; | ||
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup; | ||
|
||
public final class NotificationHelper extends AbstractNotificationPopup { | ||
|
||
private final String title; | ||
private final String description; | ||
private final NotificationType notificationType; | ||
|
||
public NotificationHelper(final Display display, final String title, final String description, final NotificationType notificationType) { | ||
super(display); | ||
this.title = title; | ||
this.description = description; | ||
this.notificationType = notificationType; | ||
} | ||
|
||
private Image getInfoIcon() { | ||
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); | ||
ImageDescriptor imageDescriptor = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK); | ||
return imageDescriptor.createImage(); | ||
} | ||
|
||
private void showStandardNotification(final Composite parent) { | ||
Composite container = new Composite(parent, SWT.NONE); | ||
container.setLayout(new GridLayout(2, false)); | ||
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | ||
|
||
Label iconLabel = new Label(container, SWT.NONE); | ||
iconLabel.setImage(getInfoIcon()); | ||
iconLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); | ||
|
||
Label notificationLabel = new Label(container, SWT.WRAP); | ||
notificationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); | ||
notificationLabel.setText(this.description); | ||
} | ||
|
||
@Override | ||
protected void createContentArea(final Composite parent) { | ||
if (this.notificationType.equals(NotificationType.CUSTOMIZATION_CHANGED)) { | ||
showStandardNotification(parent); | ||
} | ||
} | ||
|
||
@Override | ||
protected String getPopupShellTitle() { | ||
return this.title; | ||
} | ||
|
||
@Override | ||
protected Point getInitialSize() { | ||
return new Point(60, 20); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
plugin/src/software/aws/toolkits/eclipse/amazonq/util/NotificationType.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,8 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.util; | ||
|
||
public enum NotificationType { | ||
CUSTOMIZATION_CHANGED | ||
} |
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.
Let's try to avoid this tight coupling to a specific
NotificationType
. If we anticipate multiple notification types we can subclass those off a baseToolkitNotification
type. Granular text (e.g. for the customization message) should be passed in at time of use.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.
got it, then i'll also rename NotificationHelper as ToolkitNotification then and remove the NotificationType enum.